Mike Toppa here - I'm a new member to the list. I'm trying to figure out a couple things relating to wp_enqueue_script and wp_enqueue_style. I've looked at a few different blog posts people have written trying to explain these, and I'm finding incorrect advise (for example, calling them with wp_print_scripts is not a good idea).
1. I know to wrap calls to them in my own function. To use them outside the admin pages, what is the best action to call my function from? The codex says to use the init action, but that causes them to also load in the admin pages, which is undesirable. What is the best action hook to use so that they'll load in the public pages but not the admin pages? I came across a couple support threads with people suggesting the use of template_redirect, but that struck me as an odd choice (even if works, it doesn't seem like a conceptual fit).
2. Both functions want the src path defined from the root of the wordpress installation. PLUGINDIR seems to do the trick for the plugin directory. What is the equivalent for the active theme directory? TEMPLATEPATH gives the absolute path, and get_stylesheet_directory_uri() gives the absolute URL. How do I get the relative path? In my plugin I give users the option of customizing the plugin's css and placing a copy in their active theme folder, so I can't extrapolate the path from the location of my script.
I'll be happy to update the codex with the correct answers if anyone knows them.
[template_redirect] is one of the easiest filters to use after WP has loaded and parsed everything, and is ready to start outputting. when this action fires, Plugins have everything at their disposal, and the theme hasnt displayed anything yet, Very useful time to inspect and redirect if need be, or to enqueue stuff that'll be needed (since you can see the posts now)
1. In your function, just do a conditional: if(!is_admin()) { wp_enqueue_script...
}
2. the src wants a url, not a path (I think). Yes, it could be a relative url, but that can be determined based on the location of the file you're using to do the wp_enqueue_script in (../../file.js or something similar). But really, the full url should work fine, and will probably be your best bet.
On Mon, Apr 6, 2009 at 8:27 AM, Michael Toppa <pub...@toppa.com> wrote: > Hi all,
> Mike Toppa here - I'm a new member to the list. I'm trying to figure out a > couple things relating to wp_enqueue_script and wp_enqueue_style. I've > looked at a few different blog posts people have written trying to explain > these, and I'm finding incorrect advise (for example, calling them with > wp_print_scripts is not a good idea).
> 1. I know to wrap calls to them in my own function. To use them outside the > admin pages, what is the best action to call my function from? The codex > says to use the init action, but that causes them to also load in the admin > pages, which is undesirable. What is the best action hook to use so that > they'll load in the public pages but not the admin pages? I came across a > couple support threads with people suggesting the use of template_redirect, > but that struck me as an odd choice (even if works, it doesn't seem like a > conceptual fit).
> 2. Both functions want the src path defined from the root of the wordpress > installation. PLUGINDIR seems to do the trick for the plugin directory. What > is the equivalent for the active theme directory? TEMPLATEPATH gives the > absolute path, and get_stylesheet_directory_uri() gives the absolute URL. > How do I get the relative path? In my plugin I give users the option of > customizing the plugin's css and placing a copy in their active theme > folder, so I can't extrapolate the path from the location of my script.
> I'll be happy to update the codex with the correct answers if anyone knows > them.
> 2. Both functions want the src path defined from the root of the > wordpress installation. PLUGINDIR seems to do the trick for the > plugin directory.
No -- PLUGINDIR is obsolete and problematic. use WP_PLUGIN_DIR and WP_PLUGIN_URL instead.