How do I detect whether I’m on a BuddyPress page?
- 
		Howdy, 
 I’m trying to work sub-menus into my theme but am running into issues when navigating to BuddyPress pages (as opposed to standard WP pages, posts, etc.). Basically, what I want to do is have pages (where appropriate) display a sub menu, ala:http://skitch.com/zamoose/d12ns/about-us-delta-sigma-theta-sorority-inc-south-jersey-alumnae-chapter But when I navigate to pages that exist under BuddyPress’ control, I get the following: http://skitch.com/zamoose/d12nu/delta-sigma-theta-sorority-inc-south-jersey-alumnae-chapter I’m using the following to generate the sub-menu: if (is_page()) { 
 global $wp_query;if( empty($wp_query->post->post_parent) ) { 
 $parent = $wp_query->post->ID;
 } else {
 $parent = $wp_query->post->post_parent;
 }$title = get_the_title($parent); if(wp_list_pages(“title_li=&child_of=$parent&echo=0” )) { ?> 
 <ul id=”subnav”>
 <?php
 wp_list_pages(“title_li=&child_of=$parent&echo=1” );
 ?>
 </ul>
 <?php
 }
 }Where am I going astray? 
- 
		
			
The following alteration of my code seems to work in the cases that I’ve tested thus far: if ( is_page() && ( $bp->current_component == ” ) ) { I’m unsure as to whether this is an empty string or a null value for all instances, so I don’t think an is_null() call would be appropriate. If anyone knows of a BP-approved method for this, though, I’d be all ears. if ( bp_is_page( ) : No, that doesn’t work, bp_is_page() requires an argument in order to function. @zamoose – you can use the function: bp_current_component() that returns a boolean To detect specific pages, you can use bp_is_page() as @modemlooper points out. Use it like this: bp_is_page( BP_MEMBERS_SLUG ) 
 bp_is_page( BP_ACTIVITY_SLUG )
 bp_is_page( BP_GROUPS_SLUG )
 bp_is_page( BP_FORUMS_SLUG )
 bp_is_page( BP_BLOGS_SLUG )Other functions (look in bp-core-templatetags.php) include: bp_is_activity_front_page() 
 bp_is_activity_component()
 bp_is_directory()
 bp_is_home()
 …
 etc.there are lots of them To detect if you’re on a WP page use: 
 if ( bp_is_blog_page() )Vice versa, to detect if you’re on a BuddyPress page, use: 
 if ( !bp_is_blog_page() )There are some things like the activity front page that you’ll need to add to your conditional, but that’s to get you started. All conditionals can be found in /buddypress/bp-core/bp-core-templatetags.php and on this codex page (might need updating): 
 https://codex.buddypress.org/developer-docs/conditional-template-tags/Awesome! Works like a charm. 
- The topic ‘How do I detect whether I’m on a BuddyPress page?’ is closed to new replies.