Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How to add version of style.css in WordPress like below i can do in Joomla.

<link rel="stylesheet" href="/templates/example/css/style.css?v=1.2">

i know that the style.css will load dynamically. please help me to how to do that.

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

Version number is a parameter of wp_enqueue_style().

Per the Codex, here are all the parameters that wp_enqueue_style accepts.

wp_enqueue_style( $handle, $src, $deps, $ver, $media );

So for example to load a stylesheet with a version number you'd do the following:

function wpa_90820() {
    wp_enqueue_style('my-styles', get_stylesheet_directory_uri() .'/my-styles.css', '', '1.0' );       
}    

add_action('wp_enqueue_scripts', 'wpa_90820'); 
share|improve this answer
    
when i do this the old style.css is also loading. How to remove it? –  Toretto Mar 14 '13 at 12:10
    
@VinodDalvi what do you mean by handle. i don't know about it ,i m new to wordpress please me. –  Toretto Mar 14 '13 at 12:14
    
@Toretto Either you theme is hard-coding it in header.php or your theme is also enqueing it with a different handle (the first parameter). The solution also depends on if you are directly editing your theme's functions.php or if you've created a child theme. –  helgatheviking Mar 14 '13 at 12:15
    
@Toretto, $handle is shown in my response and also described in the link I provided to the Codex page for wp_enqueue_style please do your homework. –  helgatheviking Mar 14 '13 at 12:15
    
@helgatheviking how can i know the old handler name. –  Toretto Mar 14 '13 at 12:18
show 2 more comments

You can achieve this using one of the following ways :

1) Add following tag in header.php file of the theme.

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>'?v=1.2" type="text/css" media="all" />

2) Add following code in functions.php file of the theme.

function theme_styles()  
{ 
  // 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_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css', array(), '1.2', 'all' );
}
add_action('wp_enqueue_scripts', 'theme_styles');

For more information see this page.

share|improve this answer
    
when i do this the old style.css is also loading. How to remove it? –  Toretto Mar 14 '13 at 12:10
    
What is the handle of old style.css? –  Vinod Dalvi Mar 14 '13 at 12:13
    
if you are not able to find the handle then just copy and paste the whole style.css url here.. i will get it from there... –  Vinod Dalvi Mar 14 '13 at 12:19
    
Or can you tell me whats your theme name or theme's folder name? –  Vinod Dalvi Mar 14 '13 at 12:23
1  
Welcome .... :) –  Vinod Dalvi Mar 14 '13 at 12:25
show 1 more comment

This is pretty straight up way of getting the version number by calling the function bloginfo($show) twice. First for the stylesheet and secondly for the version number.

<link rel="stylesheet" id="style-css" href="<?php bloginfo('stylesheet_url'); ?>?ver=<?php bloginfo('version'); ?>" type="text/css" media="all" />

Thats all there is to it. Hope that helps or is useful. You can go through all the parameters available and see what you can output with the bloginfo() function.

Ignore my comment since @Ravs has pointed out my error regarding the 'versions' parameter for the bloginfo() function. It does indeed print the Wordpress version number.

share|improve this answer
    
I think that it is not correct answer because <?php bloginfo('version')?> gives you current wordpress version while question is about append style.css version not wordpress version. –  Ravs Jun 5 '13 at 23:25
    
@Ravs thanks for pointing that out. –  cazepeda Jun 9 '13 at 2:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.