Skip to:
Content
Pages
Categories
Search
Top
Bottom

Converting theme, how to load BuddyPress stuff on BuddyPress pages only?


  • thekmen
    Participant

    @thekmen

    Hi All,

    I am converting a WordPress theme to use BuddyPress 1.2.x features.

    I want to cut down on the page load time for normal WordPress blog posts & pages by only including the BuddyPress Ajax, JS & CSS while viewing those pages

    Currently I am using

    if ( bp_is_page( BP_ACTIVITY_SLUG ) ||  bp_is_page( BP_MEMBERS_SLUG )
    || bp_is_member() || bp_is_page( BP_GROUPS_SLUG ) || bp_is_group()
    || bp_is_page( BP_FORUMS_SLUG ) || bp_is_page( BP_BLOGS_SLUG ) ) {

    load required ajax, css & js here

    }

    is there any better way for checking if we are currently viewing a BuddyPress page or am I missing out on any BuddyPress pages with this?

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

  • r-a-y
    Keymaster

    @r-a-y

    Look at the current_component.

    <?php global $bp;
    if (isset($bp->current_component)) {
    YOUR BP CSS/JS here
    }
    ?>

    The current_component should only return something if it is a BP page.

    [EDIT]

    Just checked the activity stream home page… it doesn’t return anything for that.

    You’ll need to add a conditional for that as well.


    thekmen
    Participant

    @thekmen

    Thanks @r-a-y, using

    global $bp;
    if (isset($bp->current_component)) {
    YOUR BP CSS/JS here
    }

    seems to load the BuddyPress stuff on normal WordPress posts & pages where as my longer version doesn’t, any other ideas?


    thekmen
    Participant

    @thekmen

    @r-a-y, just checked the activity stream home page setting & you are correct, isset($bp->current_component returns false but still returns true when viewing normal WP posts & pages


    r-a-y
    Keymaster

    @r-a-y

    I only tested the current_component on one WP page… okay just tested with one post.

    It returns a number if you’re on a WP post, so do a check for is_numeric.

    global $bp;
    if (is_front_page() || (isset($bp->current_component) && !is_numeric($bp->current_component)) ) {
    YOUR BP CSS/JS here
    }

    This is untested… but give it a shot.


    thekmen
    Participant

    @thekmen

    I am getting component returned for all pages/posts, viewing a post returns something like a-post-with-everything-in-itcomponent

    viewing a group returns groupcomponent

    not getting numbers on any views, will try some more tomorrow, thanks a million for your help.


    r-a-y
    Keymaster

    @r-a-y

    Hmm okay… i’m just testing this locally with a child theme of the default BP theme. I also haven’t upgraded to BP 1.2.1 on this test box.

    Are you echoing $bp->current_component to get these results – “a-post-with-everything-in-itcomponent” and “groupcomponent”?


    thekmen
    Participant

    @thekmen

    yeah, echoing it to see what’s returned & it returns the post/page name with component tacked on, heading in the right direction though.

    Using

    if ( bp_is_page( BP_ACTIVITY_SLUG ) ||  bp_is_page( BP_MEMBERS_SLUG )
    || bp_is_member() || bp_is_page( BP_GROUPS_SLUG ) || bp_is_group()
    || bp_is_page( BP_FORUMS_SLUG ) || bp_is_page( BP_BLOGS_SLUG ) )

    still works fine, just would prefer an easier way & a way to make sure other components & plugins also work

    Thanks again.


    r-a-y
    Keymaster

    @r-a-y

    The word “component” shouldn’t be tacked on…

    I just changed my permalinks to /%postname%/ and now WP posts do not return anything for $bp->current_component.

    Needs some investigating… but hopefully that helps somebody.


    thekmen
    Participant

    @thekmen

    sorry @r-a-y, I had tacked on ‘component’ myself, my mistake.

    I had permalinks set to /%postname%/ when $bp->current_component was returning the title of the post/page.

    Just tried setting permalinks to default, and now $bp->current_component returns nothing for posts/pages, weird…


    r-a-y
    Keymaster

    @r-a-y

    That’s what we wanted though right?


    thekmen
    Participant

    @thekmen

    not really,

    I don’t want to have to use the default permalink structure (?p=123) for this to work.


    r-a-y
    Keymaster

    @r-a-y

    You don’t have to.

    Didn’t we want $bp->current_component to return blank for WP pages and posts?

    That way you can just target BP pages like profiles, member directories, etc. because $bp->current_component returns something for them.


    thekmen
    Participant

    @thekmen

    The only way I can get $bp->current_component to return nothing for normal WP posts and pages is by using the default permalink structure (?p=123), as soon as I use /%postname%/ for permalinks, $bp->current_component returns the post/page name


    r-a-y
    Keymaster

    @r-a-y

    What happens when you use the default /%year/%month%/%postname% permalink?


    thekmen
    Participant

    @thekmen

    OK, that would work for posts as $bp->current_component returns the first bit – i.e. %year% so I could use !is_numeric.

    However, it doesn’t work for pages or category archives.


    r-a-y
    Keymaster

    @r-a-y

    You might have to add a WP conditional like is_archive().

    It’s a little bit weird why you’re getting the page slug in the current_component.

    Could be because of the Hybrid theme you’re using. I’m not completely sure.


    thekmen
    Participant

    @thekmen

    Thanks @r-a-y,

    I tried switching back to the default BuddyPress 1.2.1 theme & get the exact same results.


    r-a-y
    Keymaster

    @r-a-y

    I guess we need more testers!


    thekmen
    Participant

    @thekmen

    yeah, guess so.

    Thanks @r-a-y for all your help with this.

    Just opened a Trac ticket, https://trac.buddypress.org/ticket/2131

    Hope this helps theme frameworks & conversions.


    Anointed
    Participant

    @anointed

    going to sound like a stupid question, but here goes.

    Where is the code in buddypress that is injecting the needed js/ajax etc?

    It’s definitely not in the bp-default header file.

    I managed to create a new child theme with no issues, even using my own header.php file, so it would be nice to know what code to modify once this is resolved so that I only load bp stuff where needed.


    thekmen
    Participant

    @thekmen

    @Anointed, the default theme functions.php is calling the required ajax & js.

    I want to add a function to a standard WP theme functions.php to only call those files when viewing BP pages.


    thekmen
    Participant

    @thekmen

    if ( !bp_is_blog_page ) { do this on buddypress pages }

    seens to do the trick, marking as resolved.


    r-a-y
    Keymaster

    @r-a-y

    Cool, much simpler than what I thought!


    corin-rules
    Member

    @corin-rules

    I would like to use this with the default theme, excluding the sidebar on the home and post pages.

    In which file would this code be placed?

Viewing 24 replies - 1 through 24 (of 24 total)
  • The topic ‘Converting theme, how to load BuddyPress stuff on BuddyPress pages only?’ is closed to new replies.
Skip to toolbar