我在我的网站上添加了bbpress论坛插件来处理讨论、论坛或评论。bbPress CSS文件被添加到我博客的每个页面。现在,考虑到页面速度,我只想将其加载到论坛目录。有没有办法做到这一点?
仅在论坛目录上加载bbPress css文件
3 个回复
最合适的回答,由SO网友:brasofilo 整理而成
样式在函数中排队enqueue_styles()
文件内部/wp-content/plugins/bbpress/templates/default/bbpress-functions.php
.
这是使用的问题is_bbpress()
和wp_dequeue_style
. 只有一种样式排队,但这里我们将删除所有3种可能性。
add_action( \'wp_enqueue_scripts\', \'bbpress_enqueue_wpse_87081\', 15 );
function bbpress_enqueue_wpse_87081()
{
// Check if bbpress exists
if( !function_exists( \'is_bbpress\' ) )
return;
if( !is_bbpress() )
{
wp_dequeue_style(\'bbp-child-bbpress\');
wp_dequeue_style(\'bbp-parent-bbpress\');
wp_dequeue_style(\'bbp-default-bbpress\');
}
}
SO网友:Androliyah
在标题中尝试
<?php
if(is_page_template(\'bbpress.php\' \'forum.php\' or whatever your forum template is)){
echo \'<link href="path/to/stylesheet.css" rel="stylesheet" type="text/css" />\';
}
?>
theif(is_page_template)
应该只在该页面模板上加载css。或
<?php
if(is_page(\'forums\')){
echo \'<link href="path/to/stylesheet.css" rel="stylesheet" type="text/css" />\';
}
?>
SO网友:Daniel Flöijer
brasofilo的回答对我不起作用。经过一番挖掘和修改,我成功地将“-bbpress”从队列中删除,使其正常工作。请注意,我不确定这是否是正确的解决方案。
add_action( \'wp_enqueue_scripts\', \'bbpress_enqueue_wpse_87081\', 15 );
function bbpress_enqueue_wpse_87081()
{
// Check if bbpress exists
if( !function_exists( \'is_bbpress\' ) )
return;
if( !is_bbpress() )
{
wp_dequeue_style(\'bbp-child\');
wp_dequeue_style(\'bbp-parent\');
wp_dequeue_style(\'bbp-default\');
}
}
结束