How To Disable BBPress Plugins Styles and JS in WordPress Page


When you are running a high traffic site, even cutdown 1-2 extra seconds in site load time are gold. With the installation of several WordPress Plugins which help improved your site functional and development, bulk styles and js loading could taken more extra seconds from your site load speed.

Today in particular, i will show you how to disable BBPress, BBPress Post Toolbar and BBPress GD Attachments plugin’s styles and javascripts on other page except the associated ‘forums’ page.

1. Disable BBPress default template CSS stylesheet

You can add this to your functions.php, preferly at bottom of the php file before end ?

function mp_deregister_bbstyles() {
if ( function_exists( 'is_bbpress' ) ) {
if ( !is_bbpress() ) {
wp_deregister_style( 'bbp-default-bbpress' ); 
}
}
}
add_action( 'wp_print_styles', 'mp_deregister_bbstyles', 100 );

2. Disable BBPress Post Toolbar CSS stylesheet and JS Scripts

You can add this to your functions.php, preferly at bottom of the php file before end ?

function mp_deregister_bbptstyles() {
if ( function_exists( 'is_bbpress' ) ) {
if ( !is_bbpress() ) {
wp_deregister_style( 'bbp_5o1_post_toolbar_style' );
wp_deregister_style( 'bbp_5o1_post_toolbar_uploader_style' );
}
}
}

function mp_deregister_bbptscript() {
if ( function_exists( 'is_bbpress' ) ) {
if ( !is_bbpress() ) {
wp_deregister_script( 'bbp_5o1_post_toolbar_script' );
wp_deregister_script( 'bbp_5o1_post_toolbar_uploader_script' );
}
}
}
add_action( 'wp_print_styles', 'mp_deregister_bbptstyles', 100 );
add_action( 'wp_print_scripts', 'mp_deregister_bbptscript', 100 );

3. Disable BBPress GD Attachment CSS stylesheet and JS Scripts

You can add this to your functions.php, preferly at bottom of the php file before end ?

function mp_deregister_bbgdstyles() {
if ( function_exists( 'is_bbpress' ) ) {
if ( !is_bbpress() ) {
wp_deregister_style( 'd4p-bbattachments-css' );
}
}
}

function mp_deregister_bbgdscript() {
if ( function_exists( 'is_bbpress' ) ) {
if ( !is_bbpress() ) {
wp_deregister_script( 'd4p-bbattachments-js' );
}
}
}

add_action( 'wp_print_styles', 'mp_deregister_bbgdstyles', 100 );
add_action( 'wp_print_scripts', 'mp_deregister_bbgdscript', 100 );

Final Conclusion

You might wonder what’s the different the above code can bring to your site load speed. Well before added the above code, using Pingdom Test the site load time are about 6.75s and 7.28s with 228 Requests ( tested 2 times ). As you can see, after added the code, the site load time are significanly decreased to 1.97s only and Requests are down to 217, 11 requests from BBPress and BBPress plugins were excluded.

94328 magpress pingdom test bench How To Disable BBPress Plugins Styles and JS in WordPress Page

A standard site load time below 3s is optimal for me, hopefully i can find a way to reduce page size to below 1MB at least. Using a CDN services seem like the right track.

Hope you enjoy the read, more BBPress Tips and Tricks coming this month.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>