wordpress主题更新style.css样式表文件后不生效的解决方法

  • 时间:2020-05-29 14:26:07
  • 分类:网络文摘
  • 阅读:129 次

前两天在 style.css 样式表文件中添加了几行代码,用来测试 wordpress主题效果,更新后发现主题相应页面没有任何变化,多方查找原因无果。后通过浏览器的F12调试工具发现 style.css 中看不到我添加的css代码,于是在浏览器中手动添加style样式测试成功,这说明css代码本身没有问题。百度一下据说是缓存造成的,可我即使清空浏览器缓存也看不到网页任何变化,后来找到一段代码总算解决了此问题。

将如下代码添加到当前主题下的 functions.php 文件中,这样每次更新 style.css 后效果就会立即显现出来了。

  1. add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles', PHP_INT_MAX);
  2. function enqueue_child_theme_styles() {
  3.     wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
  4.     wp_enqueue_style( 'child-style', get_stylesheet_uri(), NULL, filemtime( get_stylesheet_directory() . '/style.css' ) );
  5. }

问题虽然解决,但具体原因暂时还是没有找到,或许同网站的服务器有关吧。

推荐阅读:
7 Things Gutenberg Block Editor Does Better Than The Classic Edi  Top 6 Things to Keep in Mind While Sending Bulk Emails  7 Tweaks to Amplify Your Landing Page’s Conversion Rate  Fresh Ideas to Make Money Via Your Blog  4 Tips for Earning the Best Quality Backlinks  Lombok Code Template Tutorial: You Probably Don’t Need to   5 Easy-to-Use SEO Tools and Their Uses  The Difference Between Java Map’s compute, computeIfAbsent  How to Fix a Slow/Incorrect Clock on Windows?  How to Put Current Running Program in Background without Being T 
评论列表
添加评论