最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to change the style.css?ver=5.4.1 in Wordpress?

programmeradmin2浏览0评论

I am using WordPress and I have style page link

.css?ver=5.4.1

I have to change from style.css?ver=5.4.1 to style.css?v=<?=time();?>

Is it possible to change it?

Why I am doing this

I don't know How can I explain my issue with style. Why I am doing this because if I change anything in the style.css that is not updating on the browser. I mean, I added some css using theme editor and when I check my website then I am not getting my latest CSS. But If I go and check the theme editor then my latest code is there.

I tried everything, I haven't set any cache on my website. As of now it's totally empty. I contact GoDaddy for this issue they said we can't help in this contact your developer.

Now what I am doing is, My style.css file is totally empty and I create one more css file called main-style.css and I am adding all my css there. This file also the same issue. Then What I am doing. First I download this file then I add some css as per requirement and upload again then my css working.

I am using WordPress and I have style page link

https://example/blog/wp-content/themes/themename/style.css?ver=5.4.1

I have to change from style.css?ver=5.4.1 to style.css?v=<?=time();?>

Is it possible to change it?

Why I am doing this

I don't know How can I explain my issue with style. Why I am doing this because if I change anything in the style.css that is not updating on the browser. I mean, I added some css using theme editor and when I check my website then I am not getting my latest CSS. But If I go and check the theme editor then my latest code is there.

I tried everything, I haven't set any cache on my website. As of now it's totally empty. I contact GoDaddy for this issue they said we can't help in this contact your developer.

Now what I am doing is, My style.css file is totally empty and I create one more css file called main-style.css and I am adding all my css there. This file also the same issue. Then What I am doing. First I download this file then I add some css as per requirement and upload again then my css working.

Share Improve this question edited May 26, 2020 at 19:11 Naren Verma asked May 26, 2020 at 17:52 Naren VermaNaren Verma 2491 gold badge6 silver badges19 bronze badges 6
  • @fuxia, I want to know why you change my tags from WordPress to css? This is not a css issue? – Naren Verma Commented May 26, 2020 at 17:56
  • It is your CSS file, right? – fuxia Commented May 26, 2020 at 17:57
  • Yes the file is CSS but the issue is not CSS. – Naren Verma Commented May 26, 2020 at 17:59
  • What's the purpose? Are you trying to hide the WordPress version, or are you trying to keep your CSS file from being cached? – Pat J Commented May 26, 2020 at 19:04
  • @PatJ, No I don't want to hide WordPress version. I want whenever I update my CSS that should reflect immediately after save. Let me explain my issue in detail in the question. – Naren Verma Commented May 26, 2020 at 19:08
 |  Show 1 more comment

2 Answers 2

Reset to default 1

When you enqueue the style, you can use filemtime() as the version:

<?php
add_action('wp_enqueue_scripts', 'wpse_367594_enqueue_version');
function wpse_367594_enqueue_version() {
    wp_enqueue_style(
        // Update this to your slug.
        'style-slug',
        // Update to your stylesheet URL if it's not the main style.css.
        get_stylesheet_directory_uri() . '/style.css',
        // Include dependencies here or pass an empty array.
        array('theme-dependency'),
        // Here's the line that sets the version.
        filemtime( get_stylesheet_directory() . '/style.css' ),
        'screen'
    );
}
?>

That should bust most layers of caching so visitors see the latest version whenever the file is updated.

Finally, I got my solution, I don't know it's the best way or not but it's solved my issue.

What I did, I checked function.php file and found below code

function themename_scripts() {
    wp_enqueue_style( 'themename-style', get_stylesheet_uri(), array(), _S_VERSION );
    wp_style_add_data( 'themename-style', 'rtl', 'replace' );

    wp_enqueue_script( 'themename-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _S_VERSION, true );

    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}
add_action( 'wp_enqueue_scripts', 'themename_scripts' );

Then I remove _S_VERSION from below code and added time()

 wp_enqueue_style( 'themename-style', get_stylesheet_uri(), array(), time() );

and I got my output it is displaying like

<link rel='stylesheet' id='main-styles-css'  href='http://test/wp-content/themes/themename/style.css?ver=1597849143' media='' />
发布评论

评论列表(0)

  1. 暂无评论