[wp-hackers] questions on best practices for wp_enqueue_script and wp_enqueue_style

Michael Toppa public at toppa.com
Mon Apr 6 12:27:34 GMT 2009


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.

Thanks very much,

Mike T


More information about the wp-hackers mailing list