By the time the shortcode is evaluated as part of the_content
the header of the site has already been assembled. This makes it impossible to load scripts or styles in the header anymore.
As s_ha_dum suggests you could pre-process the whole post in the head of the file, but that would probably consume more resources than indiscriminately adding the js+css files to the header.
Another, also quite elaborate, approach would be to hook into save_post
and set a postmeta flag indicating whether the shortcode is used in the post. You could then read the flag while still in the head and include the js+css files.
Related Posts:
- Check javascript file Proper way in functions.php
- Can someone please tell me what is wrong with my plugin?
- Ajax Call not Working in Plugin
- JS working when used normally but not in wordpress
- Javascript as Jquery Function Call?
- How to include code only on specific pages?
- force enqueue script to be first in order of prominence
- All shortcodes not working on custom theme
- How do I make my wordpress page more friendly for mobile viewers?
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- How do I use WordPress PHP functions in my Javascript code?
- How to avoid redefining requirejs in plugin when another plugin also uses requirejs
- How to create popup same as wordpress popup feature
- Only execute jQuery function(on document ready) on the page has shortcode from plugin [duplicate]
- Can I share predefined fonts from theme_support with a gutenberg component?
- Pass a php string to a javascript variable
- Confused about shortcode and settings values
- Running jquery script after shortcode [closed]
- Problem in loading javascript in footer
- JQuery not working in my plugin [closed]
- Using custom JS plugins with WordPress?
- Best approach to fetch data from wp options to js file or php file
- Plugin Handle URL With Custom Theme
- How to put JQuery/Ajax inside shortcode?
- wordpress site | All-in-one-cufon IE Issue
- WordPress function not being called from jQuery method
- Change upload folder for a CPT
- Time consuming callbacks in customizer
- Modifying a .js Function for Print [QZ Tray, WooCommerce POS]
- accessing wp.media api from a tinymce plugin
- Redux Framework: Page freezes on typing in Editor
- WordPress 3.8.3. custom theme – sliders won’t load js/css files
- Using window.onload with Ubermenu
- Create shortcode to echo javascript
- Redirect to another page using contact form 7? [closed]
- Where are theme codes located for WordPress?
- “Conflict” with jQuery (or its plugins)?
- using do_shortcode
- How to add a dvi tag to a shortcode then change a generated text using jQuery
- Deactivate JS Script in Plugin Shortcode
- wordpress add_action() issue in ajax call
- How to activate a plugin on the activation of a theme?
- Localizing methods for jQuery append prepend wrap parent
- Override/ignore CSS from active theme as not to interfere with my custom CSS
- Why does my jQuery plugin show up as text in WordPress?
- JQuery needs to be defined in , but Gravity Forms is defining it in the
- Disable submit button order
- How to prevent tabs from opening all at once
- Executing Javascript in Plugin
- JS Plugin not executing the js correctly. Trying to make all internal links scroll smoothly
- Call javascript functions from each page
- Javascript from Easy-Fancybox place into footer
- Plugin Admin panel checkbox unchecked after submit
- uncaught TypeError: Cannot read properties of null (reading ‘classList’) custom plugin
- Custom Plugin scripts from admin working in frontend
- Jquery POST Ajax Return null data in wordpress
- how to display a template.php in a shortcode
- login form should redirect to register page for in 1st login next time it should redirected to home page
- Overriding inline !important CSS with Javscript code snippet with media query
- Get the link title attribute and send it google analytics as custom label via google tag manager using beehive pro for WordPress
- How to properly enqueue jQuery knob on WordPress without conflict?
- Why does my custom plugin only function correctly once per page?
- How to get a specific string from a url
- Does anybody know how to insert a complete jquery plugin into a wordpress elementor-page?
- Image path in childs theme
- WordPress site hamburger menu toggle not working
- Website always load twice on start
- How to solve Blocked a frame with origin from accessing a cross origin frame error in wordpress?
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- show-hide based on select option jquery wordpress
- Speed issues because of CSS & JavaScript
- Javascript in plugin not working
- What is the process for reimplementing a back up WordPress?
- jquery-issue: cannot load the basic jquery
- Possible jquery / library conflict in plugin usage
- Ajax, jQuery and WordPress
- Trying to override/intercept a PhotoMosaic gallery link in WordPress using jQuery
- Why won’t the Comprehensive Google Map Plugin load?
- get_option include in my adsense
- How do I output user_registered time in my correct timezone?
- Ajax in Plugins: returns the whole page
- Element works, but not on wordpress site [duplicate]
- Shortcode return is printing a 1 afterward
- Load css classes after using ajax calls
- do_shortcodes() isn’t working
- WordPress shortcode plugin not working
- FacetWP: Plugin breaks button/modal functionality inside searchable content area
- WP Customer Reviews call short code on another page [closed]
- TypeErrors with Yoast, jQuery in conflict?
- Count div with class (.length) only shows 0 [closed]
- Beginner question: Accessing js script in plugin
- How can I make content disappear when a user logs in?
- Adding Shortcode to Text Widget
- get_post_title is not working on homepage
- Jquery NoConflict Problem
- Elementor Sidebar not loading when PRO elements plugin is active
- Fatal error: Class ‘RDTheme’ not found
- How to store multiple instances of the plugin’s options for various shortcodes
- How can I modify the colors of my theme for a single section of my site? [closed]
- Problem on a wordpress website with a plugin [closed]