【发布时间】:2017-09-25 16:44:42
【问题描述】:
我正在使用带有报纸主题的 Wordpress(作为子主题)。我注意到来自子主题的自定义 CSS 被加载了两次。
我检查了function.php,我想知道第二个函数是否是我问题的根源?
if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
function chld_thm_cfg_parent_css() {
wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( ) );
}
endif;
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 1001 );
if ( !function_exists( 'child_theme_configurator_css' ) ):
function child_theme_configurator_css() {
wp_enqueue_style( 'chld_thm_cfg_child', trailingslashit( get_stylesheet_directory_uri() ) . 'style.css', array( 'chld_thm_cfg_parent','td-theme','td-theme-demo-style' ) );
}
endif;
add_action( 'wp_enqueue_scripts', 'child_theme_configurator_css' );
感谢您的帮助。
编辑 1:我通过站点代码检查器找到了这两行代码。你认为这可能是它吗?
<link rel='stylesheet' id='td-theme-css' href='.../wp-content/themes/Newspaper-lesser-old-child/style.css?ver=8.1.1504096948' type='text/css' media='all' />
<link rel='stylesheet' id='chld_thm_cfg_child-css' href='.../wp-content/themes/Newspaper-lesser-old-child/style.css?ver=8.1.1504096948' type='text/css' media='all' />
【问题讨论】:
-
它没有被您发布的代码加载,所以它必须在其他地方加载。如果不查看您的其余代码,我们就无法知道在哪里,因此您必须尝试调试您的网站才能找到它。
-
好吧 - 我不知道,我应该先看哪里。有什么建议吗?
-
我已经编辑了帖子。你认为这两条线可能是它吗?以及如何处理它?
-
是的,包含相同样式表的 2 行代码加载了两次!您的代码包含其中一个,但如果没有看到父主题中的排队代码,我不知道另一个来自哪里。我在下面汇总了一些可能的解决方案的答案 - 如果您有任何问题或要添加更多信息,请告诉我。或者,如果答案对您的问题有帮助,您可以接受它,以便您的问题在网站上被标记为已解决,其他有类似问题的用户也会知道这对他们也有帮助。它也会给我们两个代表点:)
标签: php css wordpress child-theming