WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I added bbpress forum pluggin in my site to handle discussions, forum or comments. The bbPress CSS file is added to every page of my blog. Now, I want to load it only on forum directory to consider page speed. Is there any way to do this?

share|improve this question
    
If it means anything to you, your site loads fine, and I could be wrong but the bbpress css is only executed on bbpress pages – Androliyah Feb 15 '13 at 21:25
    
Every single millisecond counts. Thanks though. – Angelo Suerte Feb 15 '13 at 21:27
    
You're welcome. – Androliyah Feb 15 '13 at 21:29
up vote 1 down vote accepted

The styles are enqueued in the function enqueue_styles() inside the file /wp-content/plugins/bbpress/templates/default/bbpress-functions.php.

It's a matter of using is_bbpress() and wp_dequeue_style. Only one of the styles is enqueued, but here we're removing all 3 possibilities.

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');
    }
}
share|improve this answer
    
Thanks! This is the one I'm looking for. – Angelo Suerte Feb 16 '13 at 0:26

try this in your header

<?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" />';
}
?>

the if(is_page_template) is supposed to load the css only on that page template.

OR

<?php
    if(is_page('forums')){
       echo '<link href="path/to/stylesheet.css" rel="stylesheet" type="text/css" />';
    }
    ?>
share|improve this answer
    
There is no bbpress template in my theme. It resides on plugin directory. Please check it out on pageantly.com. – Angelo Suerte Feb 15 '13 at 20:58
    
What is your bbpress slug? /forum? /support? – Androliyah Feb 15 '13 at 20:59
    
The slug is /forums/ – Angelo Suerte Feb 15 '13 at 21:01
    
Yeah, I think it will work, perhaps. However, using that if statement I might have duplicated the css without unhooking the other one... – Angelo Suerte Feb 15 '13 at 21:07
    
Find the file where the css is originally loaded, comment the lines out and duplicate the above to include all bbpress css links. – Androliyah Feb 15 '13 at 21:08

brasofilo's answer didn't work for me. After some digging around and changing it a bit I managed to get it working by removing '-bbpress' from the dequeue's. Note that I'm not sure if this is the proper solution.

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');
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.