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
- Adding Image in readme.txt file of wordpress plugin
- Saving Plugin settings to the database
- $wpdb->get_results() does not fetch results with unicode ‘WHERE’ clause
- Calling shortcode in wp_localize_script strips result
- Deleting images through upload folder, but not deleting from media library
- WordPress plugin installation
- Get image URL from media library in input
- How could I execute my plugin just in frontend (not in backend)
- Can wp_localize_script be used within a shortcode?
- Why my Plugin keeps deactivating automatically?
- Self deactivate plugins after an action occurs
- How to get current post user id
- switched from query_posts to WP_query, not working now?
- Ajax contact form widget plugin data not insert in database
- Homemade plugin while using Themify Ultra
- How to deal with WordPress and Pocket API to automate content curation on my hosted wordpress blog? [closed]
- WordPress get_avatar function not correct working
- Can I use Symfony components in a plugin that I want to submit to the WordPress plugin repository?
- Get Image Having the ID [closed]
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- How to upload large media file in chunks, without any plugin?
- How to store a secret for a plugin inside public_html
- How to use functions found inside pluggable.php with my plugin files
- Shortcode generated widget to appear on same line as heading text and button
- Get Core Functionality from Within a (Secondary) Plugin File
- Output pure JSON wordpress
- Activate plugin button do nothing [closed]
- add_meta_box showing blank screen in my page
- Plugin translations are not loaded from translate.wordpress.org
- Use inline callable for hooks and filters