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

Vid Luther vid at zippykid.com
Fri Jun 15 12:48:38 UTC 2012


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().

I noticed that the docs here are sparse:
http://codex.wordpress.org/Plugin_API/Filter_Reference#Template_Filters

What I want the following code to do:

print out a string in the format of
$websitehost/wp-content/themes/$theme/style.css?v=timethefilewaslastmodified

What I'm seeing:

http://wordpress.zippykid.dev/wp-content/themes/twentyeleven/style.css?v=1339616402added
as the first line of the html that's returned.

When I change the last line of the function to return $cssuri; I get
nothing (even the call for bloginfo('stylesheet_uri') returns a blank
string as the value for href='' )




add_filter('stylesheet_uri', zk_css_versioner());

/**
 * the goal of this method is to append a query string to the css url for
the site.
 * the query string currently is determined by the last time the css file
was modified
 * the theory is that if the file is modified, change the value of v=,
which should
 * force the CDN to pull a new version from the origin server. This could
be a
 * a hit on performance, not sure yet. Let's get it working first.
 *
 * @return string
 */
function zk_css_versioner() {


    $cssfile = get_stylesheet_directory() . "/style.css";

    if (file_exists($cssfile)) {
        $cssuri = get_stylesheet_uri() . "?v=" . filectime($cssfile);
    }

    echo $cssuri;
}
On Fri, Jun 15, 2012 at 12:34 AM, Ryan McCue <lists at rotorised.com> wrote:
>
> However, that's probably not your issue. The "bad one" that you don't want
> is hardcoded into header.php in the theme:
>
> <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo(
> 'stylesheet_url' ); ?>" />
>
> The way I'd change it is to filter that instead.
>
> add_filter('stylesheet_url', function () {
>        return get_stylesheet_directory_uri() . '/css/style.css';
> });
>
>
> --
> 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