I'm developing a plugin that use shortcodes to display some "special" buttons on frontend. These shortcodes generate HTML, CSS and JavaScript for the button so, if the user insert multiple shortcodes in the same page (to have more than one button), the same JavaScript code is repetead for each shortcode (button). How can I allow the user to insert multiple buttons in the same page without replicate JavaScript code more than one time?

For example: if the user insert 3 buttons on the page when one of these buttons is clicked the click event handler function is exectuted 3 times...

  • at the very least, use a js file for your js functions... then enqueue it.. Dec 23, 2019 at 9:12
  • I'm trying this way, it seems to be the correct solution, thank you!
    – icolumbro
    Dec 23, 2019 at 9:35


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.