[wp-hackers] a newbie question on wp_enqueue_scripts and an action or a filter

Ryan McCue lists at rotorised.com
Fri Jun 15 12:56:46 UTC 2012


Vid Luther wrote:
> Ok, I'm clearly not understanding the chain of events properly. Based on
> what Ryan and Chip said, and understanding that wp_enqueue_script isn't run
> in wp_head().

So, walking through it:

1. twentyeleven/header.php is loaded
(Some stuff happens here)
2. The start of the <link> tag is output
3. The stylesheet URI is output
4. The rest of the <link> tag is output
(More stuff here)
5. wp_head() is called
5a. Enqueued scripts are output

Note that these are separate. Enqueued styles are output during 
wp_head(), but the other output is hardcoded in the file and not 
related. The reason you're getting two <link> tags is because the first 
one in header.php is being output, then your enqueued one is being 
output later.

> add_filter('stylesheet_uri', zk_css_versioner());

The second parameter to add_filter() is a callback, which in PHP is 
represented as a string for normal functions. What this is doing is 
taking the result of that function, and attempting to hook that function 
in as a filter (and the 'http://.../style.css' function does not exist, 
causing problems).

Try using a string instead:

     add_filter('stylesheet_uri', 'zk_css_versioner');

>      echo $cssuri;

This should be returning the string instead of echoing it. The filter 
calls your callback and takes the result of that as the value that it 
will output.
-- 
Ryan McCue
<http://ryanmccue.info/>


More information about the wp-hackers mailing list