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

Ryan McCue lists at rotorised.com
Fri Jun 15 05:34:20 UTC 2012


Vid Luther wrote:
> Hi everyone,
>   Here's what I'm trying to do.
>
> I want to append the "version" parameter I send to wp_enqueue_scripts based
> on some external factors. Using the example in the code for
> wp_enqueue_scripts as inspiration, I whipped the following snippet up.
>
> function theme_styles() {
>
>     $cssfile = get_stylesheet_directory() . "/style.css";
>     if (file_exists($cssfile)) {
>         $version = filectime($cssfile);
>
>         // Register the style like this for a theme:
>         // (First the unique name for the style (custom-style) then the src,
>         // then dependencies and ver no. and media type)
>         wp_register_style('dd', get_template_directory_uri() .
> '/css/style.css', array(), $version, 'all');
>
>         // enqueing:
>         wp_enqueue_style('dd');
>     }
> }

As Chip stated, you're checking two different files here, 
$stylesheet_dir/style.css and $template_dir/css/style.css (note there's 
two differences, you should stick to the stylesheet directory for all of 
those).

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/>


More information about the wp-hackers mailing list