• Hello,

    I noticed that with many plugins, they include scripts and stylesheets in the header even if the shortcode is never used, or not used on the current page. Since this adds to the HTTP requests unnecessarily, I am trying to figure out how to conditionally include the scripts and stylesheets only if the shortcode is present.

    The shortcodes are registered with:
    add_shortcode(‘foo’, ‘my_foo’);
    However, it does not appear that I can set a variable in the my_foo() function to tell init, enqueue or wp_footer, wp_head, wp_print_* to then include any of the CSS or javascripts only if the shortcode is present on the page.
    I would like to only include the CSS as necessary, and only include the Javascript in the footer, not the header.

    Do any of you have a solution to this?
    Thanks in advance!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Conditionally Adding Scripts and Styles if Shortcode present’ is closed to new replies.