The WordPress enqueue system should prevent the inclusion of the same script multiple times, and does when I test it. For example, the following enqueues a Core script and echo
s a counter. If I put this shortcode into a post 4 times, I get “0123” but the media script only loads one time. The same test works with several other scripts I tried.
function my_shortcode( $atts, $content = null ) {
extract(shortcode_atts(array(
'title' => '',
), $atts));
static $counter = 0;
echo $counter++;
wp_enqueue_script('wp-mediaelement');
}
add_shortcode('enq','my_shortcode');
If you are getting the same script loaded over and over, there is a problem with your site, but I am not sure where start guessing at what.
Related Posts:
- Pass $this to function nested in another public function of the same class
- Create shortcode to echo javascript
- Why am I unable to load scripts in head in plugin?
- How to add a shortcode button to the TinyMCE editor?
- Conditionally enqueue a widget’s script/stylesheet in HEAD (only when present on page!)
- Custom media upload content for inserting custom post shortcode
- Loading external page template and enqueue script from plugin causes 403 forbidden error
- Checking if an attribute exists in a shortcode
- When can you get current page ID and initialize hooks right after?
- Which method is best to enqueue scripts
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- How To Ignore a Filter On Applying Filter the Content In a Function
- Shortcode display outside the div
- Declaring script dependencies between scripts enqueued with different action hooks
- shortcode doesn’t work
- Dequeue / Deregister script and replace it with a new plugin
- Custom data-id wp_enqueue_script
- How to add inline css/js inside a shortcode
- wp_enqueue_scripts not working inside shortcode
- wp_enqueue_script fails to include in footer
- Only execute jQuery function(on document ready) on the page has shortcode from plugin [duplicate]
- Avoiding Duplicate function names in Post Loop (WP_Footer script)
- Demystifying and understanding shortcode nomenclature
- Any Short code Availble for Get Post List With Thumbnail Plugin?
- Where to call add_shortcode function in WordPress Plugin Boilerplate?
- React JSX in WordPress Plugin Development
- Input with spaces in Shortcode attributes overwritten by defaults
- Allow users of my plugin to define their own shortcode rather than use mine?
- Making a plugin only available on the front-end for the logged in super admin
- Enqueue WordPress plugin scripts below all other JS
- Making a Template for a CPT created by a plugin
- creating html reusable blocks via shortcodes
- Single API call exposed via shortcode with params
- Making sure that a plugin’s scripts and stylesheets are included for dynamicaly loaded content
- jQuery for custom plugin not working with Divi theme
- Creating shortcodes in plugin
- How to create a custom shortcode based on the layout?
- Inject HTML meta tag inside wordpress tag using add_shortcode
- How can I remove the WordPress-Version (?ver=5.x) from my plugin
- Redirect to another page using contact form 7? [closed]
- Namespaced shortcode?
- How can I run a custom shortcode function on a live site and only run if the viewer is a specific machine?
- How to add a dvi tag to a shortcode then change a generated text using jQuery
- Deactivate JS Script in Plugin Shortcode
- IF condition based on wp_remote_get output
- Shortcode Attributes to Return different $_POST
- How to use template inside plugin shortcode with variables for big HTML code
- strange shortcode error: does shortcodes requires any dependency?
- How to rewrite URL and get the values?
- Custom CSS not being added by plugin
- why the wp_register_script doesn’t work for register_activation_hook
- WordPress load same script two times
- Why won’t wp_enqueue_script work within any plugin file?
- wordpress plugin add page when activate
- Thumbnail image doesn’t show up in Shortcode output
- list of custom post by custom field in frontend
- Shortcode do not return the right data in post
- How to call function in WordPress on button click?
- Hide content for specific users with id
- Why is my shortcode not working?
- WP Plugin CSS not being applied to page
- Modify Plugin PHP Class in Child Theme – Correct Method
- Shortcode in a blog post, footer and related products stop working
- shortcode which is introduced into entry the blog, and appears in side bar
- Why function hooked using object are executing at all time?
- Shortcode registered from a plugin not recognized
- Any way to hook into WP after a page displays?
- wp_enqueue_script doesn’t load JS in plugin
- Shortcode cannot parse attributes within double quotes. ” is becoming ” breaking my shortcode
- Display file contents within Plugin
- Frontend Enqueued Files in the Backend
- correct way to enqueue js and css files for wordpress shortcode?
- How to get next day date of a specific day
- Custom Plugin not Displaying in the Website Production environment (Divi)
- How to edit link for comment count
- Create “new pages” within the admin section of plugin
- A question of etiquette when forking a plugin? [closed]
- how to request a script more than once in wordpress
- Select Form Element Not Saving from Plugin Options
- The “Child Pages Shortcode” plugin, block template
- My widget won’t update its values when save is clicked
- How to log custom plugin error to debug.log file
- Quick press publish post hook
- Add a Custom Field in Comment Box next to the Text area
- How do you create a re-useable HTML fragment in wordpress
- using wp_footer hook in a plugin
- Is there any way to inject text onto pages?
- Next Previous Post in wordpress with previous / next link with title?
- How to use existing hook in twentytwelve to all theme of wordpress?
- How can I achieve this, using shortcodes
- WordPress Feed Creator Name Tag Full Name Instead Of First Name
- count the number of views of a post excluding own views
- How to get a notification when the plugin is installed?
- Does WordPress check for updates of a plugin via plugins root folder name?
- WordPress plugin with its own “site”/theme
- Delete data from custom table when deleting a post
- How to enqueue some javascript source once per page
- Create Short code dynamically
- How To Create A File Archive in WordPress?
- How to embed a new string in url?