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 echos 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
- How to get next day date of a specific day
- How to customise the output of the WP image gallery shortcode from a plugin?
- How to fetch serialized data from wordpress options
- How to get the custom page get_permalink?
- Advanced Custom Fields into functions.php
- nonces in custom oop plugin
- Wp die causing 500 Internal Server Error?
- AddToAny shortcode in the loop
- Error with get_price (and others) in self-written plugin to show price
- manage_{taxonomy}_custom_column not working
- Suitable hook when creating, updating and deleting posts programmatically
- Scripts don’t enqueue after removing plugin
- add_meta_box showing blank screen in my page
- How to be Variables and options must be escaped when echo’d?
- How to override plugin function in code snippets WordPress
- How can I gather forums posted by visitors from different sites in one place? [duplicate]
- How to make content as required in custom post type?
- How to create a “Most Popular” & “Latest” TAB in WordPress
- is_user_logged_in() undefined at shutdown in plugin context
- What are Seeds? [closed]
- Plugin translations are not loaded from translate.wordpress.org
- Use inline callable for hooks and filters
- Error in using ‘admin_enqueue_scripts’ action through a class
- How do i fix this error?
- WordPress 6.3 with datatables – cannot seem to pass json from php to javascript
- Mixed results with is_page() WordPress function, when using $this, or self
- I have created a custom plugin. After activation it creating page but i am not getting how to add another php file at page content?
- Custom Search Function in WordPress Returns No Results
- Gutenberg Blocks and Elementor