Conditional bbPress 2.3 styles and scripts

Written by Alexis Nominé on . Posted in WordPress

bbPress is one of the best forum plugins available for WordPress. However, one shortcoming of the current version (2.3) is that styles and scripts are loaded on every WordPress page even if not needed. This is not a best practice in for your website performance. Here is a quick fix for that:

In a plugin or in the functions.php file of your theme, just add:

// clean bbpress stuff outside of bbpress
add_action( 'wp_head', 'conditional_bbpress_head', 9 );
function conditional_bbpress_head(){
	if( !is_bbpress() )
		remove_action( 'wp_head', 'bbp_head' );
}
add_action( 'wp_enqueue_scripts', 'conditional_bbpress_scripts', 9 );
function conditional_bbpress_scripts(){
	if( !is_bbpress() )
		remove_action( 'wp_enqueue_scripts', 'bbp_enqueue_scripts' );
}

Now, the head should be cleaner on every other part of your site, and the loading time greatly improved.

Tags: , ,

Trackback from your site.

Leave a comment