Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do I detect whether I’m on a BuddyPress page?

Viewing 6 replies - 1 through 6 (of 6 total)

  • Doug Stewart
    Participant

    @zamoose

    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.


    modemlooper
    Moderator

    @modemlooper

    if ( bp_is_page( ) :


    Doug Stewart
    Participant

    @zamoose

    No, that doesn’t work, bp_is_page() requires an argument in order to function.


    Roger Coathup
    Participant

    @rogercoathup

    @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


    r-a-y
    Keymaster

    @r-a-y

    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/


    Doug Stewart
    Participant

    @zamoose

    Awesome! Works like a charm.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How do I detect whether I’m on a BuddyPress page?’ is closed to new replies.
Skip to toolbar