BuddyPress will soon only load its JavaScript and Style assets into the community area of your site

For quite a long time, BuddyPress users has regularly requested us to improve how the plugin’s JavaScript and Style assets are loaded into the front-end of their WordPress site.

How come BP JavaScript and CSS files are loaded everywhere on my site?

A BuddyPress user probably wishing it wasn’t the case!

That’s the question I’m often asked about BuddyPress, maybe you wondered about it too 😁. We’re not sure there’s a specific reason explaining this fact. As it was necessary before we introduced the BP Theme Compat API (see the 1.7 version announcement post) to use a BuddyPress compatible theme like the one we bundle by default (BP Default), I think we kept the way this theme was loading these assets into the first Template Pack (BP Legacy) we added to BuddyPress.

Let’s only load what we need when we need it… progressively!

In version 11.0.0 we are taking a first step towards restricting JavaScript and Style assets loading to BuddyPress pages only (or what I also call the community area of your WordPress site). To take no risks with potential BP plugins or themes needing these assets, we will carry on loading these everywhere on your site in 11.0.0. BUT if you want to avoid this, you now have an easy way to only have these loaded into the community area of your site. Simply put a bp-custom.php file in place (or use the one you already put in place) and add the following code into it:

add_filter( 'bp_enqueue_assets_in_bp_pages_only', '__return_true' );

If using the above filter, you notice something is going wrong with your website due to the use of a specific BP plugin or theme, report it here and we’ll then have another development cycle to fix things before we completely restrict these assets to BuddyPress generated pages in a second step & in version 12.0.0.

To read more about the story of this change, you can have a look at this ticket #8679.

#11-0-0, #developer-documentation