put wp_enqueue_script() in your shortcode handler.
add_shortcode('myshortcode', 'my_shortcode_handler');
function my_shortcode_handler($atts) {
wp_enqueue_script('my-script', plugins_url('my-script.js', __FILE__), array('jquery'), '1.0', true);
// actual shortcode handling here
return "bacon flavored shortcode here";
}
this definitely loads the my-script.js file for me. it gets loaded in the footer though. i don’t think there is a way for it to load conditionally in the header as it won’t have gotten to the post content to know whether the shortcode is used or not.
check this:
http://scribu.net/wordpress/conditional-script-loading-revisited.html
Related Posts:
- Styles and Scripts, Selectively enqueue across entire site
- Unable to load stylesheets and scripts to plugin settings page
- Minimizing scripts & css files that plugins add
- Best way to overide plugin CSS?
- How can I use WordPress functions in my stylesheet?
- Conditionally enqueue a widget’s script/stylesheet in HEAD (only when present on page!)
- Restricting a Plugin to Only Load its CSS and JS on Selected Pages?
- How can I create a bash install script for my WordPress sites setup (WP+plugins+theme)?
- How do I cleanly override a plugin’s CSS with a child theme?
- Why does wp_enqueue_style() in plugin not load stylesheet?
- how to include other plugins css files in a shortcode?
- How can I reduce the amount of files loaded/included per plugin?
- How can I dequeue a Plugin Stylesheet?
- Using standard backend elements in Plugin
- Using tabs for wordpress plugin
- Some way to Flush or Overwrite all Imported Content in a Site for a Fresh Import – How?
- Override CSS settings of plugins
- How can I make content disappear when a user logs in?
- Add CSS animation as Preloader to WordPress
- Best way to inject css into admin_head in plugins?
- wp_enqueue_style in Plugin [duplicate]
- Quote rotator in the sidebar
- Make the css of the widget overwrite theme css
- How can I enqueue a style only when a particular widget is active?
- WordPress Plugin Look & Feel
- Add CSS class to add-to-cart button, Woocommerce [closed]
- How to load all plugins CSS after child theme CSS?
- I need to generate the CSS for my plugin from a function, how do i map a request to a function in the front-end?
- How do I register a stylesheet inside a WordPress widget?
- Prevent CSS/JS loading when plugin is not used
- Override Theme CSS with CSS from a plugin
- Styling readme.html in plugin?
- Layout shop page: resize images and columns
- How extend shortcode default values for a plugin?
- wp_enqueue_style specifics for overwriting plugin styles
- How to override my plugin’s php classes with duplicates that are in my child theme folder
- Is it possible to use Snap Scrolling? [closed]
- Image resizing on home page (product category) [closed]
- W3 Total Cache: Load CSS asynchronously for better PageSpeed score? [closed]
- How do I write into a file (css)
- ‘Customize’ button in admin bar for CSS
- Why isn’t “background-image: url”working with Bootstrap carousel on WP?
- How to add page using HTML, CSS and JS?
- Overwrite or Replace code in WP_Footer
- How to generate CSS from a shortcode within a plugin
- Custom CSS for plugin form
- How do I modify the position of a plugin?
- plugin style conflicts, how to override? [closed]
- Is there an earlier hook than login_head or login_enqueue_scripts?
- How to disable CSS rule in Twentythirteen style.css?
- Theme’s default styles are overriding my plugin’s custom CSS
- Remove ALL css for a specific plugin page
- Globally register styles but enqueue them selectively
- CSS from textarea in options page to frontend what to do
- custom changes removed after plugin update
- W3 Total cache “empty all caches” and no stylesheets render [closed]
- Admin Panel pagination link styles
- How to style the RSS wordpress?
- Can someone please tell me what is wrong with my plugin?
- How Do I Figure Out What File(s) to Edit from Looking at the Source Code [closed]
- Scripts at the end of the page
- WPBakery JS composer unused css [closed]
- How to tie dark mode with prefers-color-scheme webkit? [closed]
- Trouble with plugin styles in admin area of WordPress
- Add a CSS class based on categroy id to archive pages
- Changing “elapsed time” to “time remaining” on MP3-jPlayer audio player with CSS or PHP changes
- Child Pages Short Code plug-in and hover capabilities?
- Removing included CSS file that doesn’t exist
- How to hide CSS by default and show on button press
- (Sticky Row) How do i make a row sticky in wpbakery page builder?
- How to create an input field, and base the output on spreadsheet data? [closed]
- WordPress plugin output formatting
- how to access all user dashboard on fronted page [closed]
- What would I need to write into a custom plugin in order to add a switch for a custom string of CSS to the edit page?
- Bootstrap and Custom CSS in custom plugin are being overwritten by theme
- Ajax Search Lite: Customize Autoscroll
- Delete mobile menu button [closed]
- Widgets Scripts don’t load – but load when I reload the page
- Ability to automatically redirect a URL
- How to get DEFER or ASYNC attribute to appear when I add a stylesheet with wp_enqueue_style from a plugin? [duplicate]
- Which filter affects the ‘entry-title’ post class
- Adding CSS to custom post type admin page causes error
- How to use my menu PHP code as sidebar?
- Add script into front from my plugin
- Redirect to another page using contact form 7? [closed]
- Edit External CSS
- Stop Plugin from Getting Styles from Other Plugin
- How do I use add_action on custom widget?
- Why Do I get “wp_remote-get: could not handle for fopen()”?
- How to apply next/previous classes to LIs for pagination links?
- Override plugin styles via my custom theme
- How to add CSS via custom plugin?
- Plugin Theme CSS [closed]
- Full list of registered scripts or styles, but from an admin options page
- Overwrite a plugin’s CSS?
- Combining several CSS files into one for optimization
- How to add a dvi tag to a shortcode then change a generated text using jQuery
- how to prevent all css and javascripts files from loading
- Front-end CSS Library for plugin [closed]
- Register Script in Plugin Widget