【问题标题】:Can't enqueue newer style.css changes in wordpress无法在 wordpress 中将更新的 style.css 更改排入队列
【发布时间】:2018-04-22 18:19:54
【问题描述】:

我无法加载我对 wordpress 主题所做的较新的 style.css 更改,它会拉取该文件的旧版本/忽略我所做/保存的任何新更改。

在我的主题文件夹“humescores”根目录下的functions.php中,我有这个来排队我的样式表

function humescores_scripts() {
        //Enqueue Google fonts: Source Sans Pro and PT Serif
        wp_enqueue_style('humescores-fonts','https://fonts.googleapis.com/css?family=PT+Serif:400,400i,700,700i|Source+Sans+Pro:400,400i,600,900');

    //Connects style.css
    wp_enqueue_style( 'humescores-style', get_stylesheet_uri() );

    wp_enqueue_script( 'humescores-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );

    wp_enqueue_script( 'humescores-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );

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

目录结构

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    试试这个,

    function humescores_scripts() {
            //Enqueue Google fonts: Source Sans Pro and PT Serif
            wp_enqueue_style('humescores-fonts','https://fonts.googleapis.com/css?family=PT+Serif:400,400i,700,700i|Source+Sans+Pro:400,400i,600,900');
    
        //Connects style.css
        wp_enqueue_style( 'humescores-style', get_stylesheet_uri(), array(), time());
    
        wp_enqueue_script( 'humescores-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
    
        wp_enqueue_script( 'humescores-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
    
        if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
            wp_enqueue_script( 'comment-reply' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'humescores_scripts' );
    

    【讨论】:

      【解决方案2】:
      wp_enqueue_style('YOUR_NAME_STYLE', get_template_directory_uri() . '/style.css');
      

      【讨论】:

      • 虽然wp_enqueue_style( 'humescores-style', get_stylesheet_uri() ); 不做同样的事情,但我的排队风格有什么问题?
      【解决方案3】:

      First确保你写了正确的路径来调用style.css file你可以调用style file with two method

      1. wp_head() 函数在页面头部或call the function name in the header page that call style files or scripts files

        在您的情况下,您的函数名称是 humescores_scripts() 调用此 页眉中的功能

        <?php humescores_scripts(); ?>
        

      也可以在header页面调用主样式文件

      <?php wp_enqueue_style( 'style', get_stylesheet_uri() );?>
      

      确定此操作后,从键盘按shift+f5fn+f5 刷新并重新下载浏览器中的文件缓存

      【讨论】:

      • 啊好吧,我实际上是在徘徊强制清除缓存快捷按钮是什么。我的排队风格有什么问题wp_enqueue_style( 'humescores-style', get_stylesheet_uri() ); 不做同样的事情吗?
      • 我编辑我的答案在the header page@Kagerjay 中调用你的函数名称
      【解决方案4】:

      发现问题

      google chromium 决定忽略更改(因为更改太小,我只编辑了 h1 标签颜色) 所以我清除了浏览器缓存,并刷新了页面,它现在可以工作了

      https://codex.wordpress.org/I_Make_Changes_and_Nothing_Happens

      【讨论】:

      • 事后加载谷歌浏览器和谷歌铬,通过浏览器同步,我没有清除chrome缓存,它仍然有原始问题,但是清除缓存后铬没有,所以我就是这样知道这是浏览器问题
      猜你喜欢
      • 2018-12-04
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      • 2021-11-13
      • 1970-01-01
      • 2017-06-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多