WordPress.org

Ready to get started?Download WordPress

Forums

Add script and css to header from withing shortcode (2 posts)

  1. quokka
    Member
    Posted 3 years ago #

    Hi,
    Trying to write a plugin. Would like to use wp_enqueue_script and wp_enqueue_style on init from within my plugins shortcode.
    Is there a way to add css and javascript to page header from within a shortcode?

    Anything pointing me in right direction is highly appreciated!

    Thanks!
    Quokka

  2. cjoseph
    Member
    Posted 3 years ago #

    Hi,
    in the case of javascript it will be a better solution to load it in the footer. And based in a shortcode you will not be able to load anything in the header because the page will be processed in the following order:
    1.header
    2.body(here will be the shortcode)
    3.footer
    So you when you will trigger the action by shortcode, the header it will be already processed.
    If you are interested study this page : http://scribu.net/wordpress/optimal-script-loading.html and you can check out my plugin based on that page. The plugin name is: activator.
    About CSS cant tell you much, currently I do some studies about it.
    best regards
    cjoseph

Topic Closed

This topic has been closed to new replies.

About this Topic