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

Vid Luther vid at zippykid.com
Sat Jun 16 16:09:34 UTC 2012


Thanks for the walkthrough and the pointer on the callback, Ryan.

I have it working now, at: https://gist.github.com/2941787

We're going to test it out now and follow up on any performance issues we
run into, with this.

On Fri, Jun 15, 2012 at 7:56 AM, Ryan McCue <lists at rotorised.com> wrote:

> 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/>
> ______________________________**_________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.**com <wp-hackers at lists.automattic.com>
> http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
>



-- 
Vid Luther
CEO and Founder
ZippyKid
Managed Wordpress Hosting
http://zippykid.com/
210-789-0369


More information about the wp-hackers mailing list