【问题标题】:why my stylesheet is not applying my style which I code newly even when it is included properly in wordpress为什么我的样式表没有应用我新编码的样式,即使它正确包含在 wordpress 中
【发布时间】:2016-12-10 12:27:44
【问题描述】:

我正在制作 wordpress 设计,并使用 wp_register_style 和 wp_enqueue_style 函数将其包含在内。 function.php 中的代码如下:

function themeSetup (){

    wp_register_style( 'prostyle', get_template_directory_uri() .'/common/prostyle.css', array(), null, 'all' );
    wp_enqueue_style( 'prostyle' );

    wp_register_style( 'style', get_stylesheet_uri(), array(), null, 'all' );
    wp_enqueue_style( 'style' );

    wp_register_script( 'JqueryCDN', 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js', '', null, false );
    wp_enqueue_script( 'JqueryCDN' );

    wp_register_script( 'proscript', get_template_directory_uri() .'/common/proscript.js', '', null, false, false );
    wp_enqueue_script( 'proscript' );


}

add_action('wp_enqueue_scripts', 'themeSetup');

主要问题:我之前编写的 css 正在网站上运行,但包含在同一文件中的每个新 css 规则既没有显示在浏览器上,也没有应用于元素。

请告诉我这些代码中缺少什么。如果 wp_register_script 或 style 函数有任何错误,请告诉我。

【问题讨论】:

  • 刷新浏览器缓存 (CTRL+F5) 可能没有注意到 css 文件已更改,因此浏览器不会重新下载
  • 是的,它有效,但我不明白为什么它不会发生在简单的点击?是因为wordpress功能吗?有什么解决办法吗?
  • 这不是 WP 问题,而是一般缓存问题
  • 感谢@riggs 的解决方案

标签: php css wordpress


【解决方案1】:

第 1 步:在 chrome 的情况下始终使用私人窗口或隐身模式。

第 2 步:禁用缓存插件(如果有)。

第 3 步:以您的风格附加版本,强制服务器使用较新的版本。

第 4 步:Cloud Flare 不会将您的 CSS 视为更新版本。

【讨论】:

  • Vasim,你的建议看起来很酷,但我不知道要执行第 3 步,所以请为我解释一下,如果可能的话告诉我避免第 4 步问题的解决方案。
  • wp.style.css?ver=1.0 中的 gogle 样式表版本控制
  • 我在 wordpress 中使用了 w3tc 并附加了 cloudflare,所以当从 w3tc 清除时,它也会自动刷新 cloudflare
  • 感谢您的帮助。
猜你喜欢
  • 2018-06-26
  • 2011-12-30
  • 2021-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-13
  • 2013-05-06
  • 1970-01-01
相关资源
最近更新 更多