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

Vid Luther vid at zippykid.com
Fri Jun 15 04:31:51 UTC 2012


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');
   }
}

add_action('wp_print_styles', 'theme_styles');

The action runs without any errors, but the problem is that I end up with
two lines for style.css, one with the auto version I want, and the other
without.

The bad one:
<link rel="stylesheet" type="text/css" media="all" href="
http://wordpress.zippykid.dev/wp-content/themes/twentyeleven/style.css" />

The good one:
<link rel='stylesheet' id='dd-css'  href='
http://wordpress.zippykid.dev/wp-content/themes/twentyeleven/css/style.css?ver=1339616402'
type='text/css' media='all' />

My question is.. how do I add the version to the first call of style.css,
and then not load it again?


More information about the wp-hackers mailing list