Conditional enqueue in header
-
Hi bbPress community,
Thank you for all your collective hard work on this great plugin. I’m working on an integration of the new 2.1 plugin into my own theme, and I had a question about scripts and styles that bbPress enqueues into the wp_head.
In general, for plugins which are highly localized on the site (ones that only get used in very specific places), I prefer to conditionally enqueue styles and scripts to keep the head section of the main site relatively clean. bbPress currently initializes the following code site-wide:
/** Scripts ***********************************************************/ add_action( 'bbp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); // Enqueue theme CSS add_action( 'bbp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); // Enqueue theme JS add_filter( 'bbp_enqueue_scripts', array( $this, 'localize_topic_script' ) ); // Enqueue theme script localization add_action( 'bbp_head', array( $this, 'head_scripts' ) ); // Output some extra JS in the
Normally I’m fairly handy with actions and filters in my functions.php file, but I’ve had a load of trouble getting these scripts to conditionally enqueue. Ideally, I would want to condition them on is_bbpress(). Can anyone offer a snippet to filter these unless is_bbpress() is true?
Thanks in advance, and let me know if my question is unclear in any way.
Andrew
- You must be logged in to reply to this topic.