Skip to:
Content
Pages
Categories
Search
Top
Bottom

Editing Group and Forum page title tags

  • @snark

    Participant

    I am running a fresh installation of BP 1.2-RC2 for WP 2.9.1 single user. Looking for help on how to edit the proper files to customize the title tags on the various Group and Forum pages. Currently, they title tags generated are generic, redundant, and not helpful for SEO:

    Group Directory

    MySite | Groups | GroupName | Forum

    Forum Directory

    MySite | Groups | GroupName | Forum

    Forum Topic Page

    MySite | Groups | GroupName | Forum

    I would like to remove the words “Groups” and “Forum”, and add the Topic title to the Title tag for the Forum Topic pages, so they had titles like this:

    MySite | GroupName | TopicTitle

    Yes a plugin would probably be preferred, but none do the job yet with Buddypress/single-user WP. The All-In-One SEO plugin is nice, but it only affects blog pages, not Buddypress Group and Forum pages, which is where I need help. The Buddypress-SEO plugin is pretty primitive, not updated, and only works with the Groups pages, not the Forum pages.

    Does anyone have a solution to this? It is a pretty major issue, and it seems like displaying the topic in a topic Title tag should be a default setting anyway. Thanks.

Viewing 20 replies - 1 through 20 (of 20 total)
  • @snark

    Participant

    Note the title of this Buddypress Forum page is displaying the title of the page, as it should:

    BuddyPress.org –> Forums –> Editing Group and Forum page title tags

    Is this a custom edit of the core files, or is there a setting somewhere that I’m missing?

    @snark

    Participant

    Any ideas?

    @aekeron

    Participant

    This site is using a separate bbpress install rather than the BuddyPress inbuilt group forums. That’s why it looks different here.

    Sorry, I know that’s not much help for your problem though.

    @boonebgorges

    Keymaster

    Should be easy to customize this the way you want it.

    Put this in functions.php of your theme:

    function my_page_title( $title, $b ) {
    global $bp;

    if ( $bp->current_action == 'forum' && $bp->action_variables[0] == 'topic' ) {
    if ( bp_has_topic_posts() ) {
    $topic_title = bp_get_the_topic_title();
    $title .= ' | ' . $topic_title;
    }
    }
    return $title;
    }
    add_filter( 'bp_page_title', 'my_page_title', 10, 2 );

    Obviously this might not be exactly what you want, but you should pretty easily be able to customize it to say whatever you want, for different kinds of pages.

    @snark

    Participant

    Thanks Boone, that’s great! I really appreciate it. It’s perfect for displaying the page title — if you or anyone else could show how, in a function like this, to strip out the generic directory names like “Groups” and “Forum” from the title, so that the end result looks like this:

    MySite | GroupName | TopicTitle

    Then I’d be all set. I’m sure someone will eventually create a plugin to customize the Titles sitewide in Buddypress, but in the meantime this is a great start. Thanks.

    @boonebgorges

    Keymaster
    function my_page_title( $title, $b ) {
    global $bp;

    if ( $bp->current_action == 'forum' && $bp->action_variables[0] == 'topic' ) {
    if ( bp_has_topic_posts() ) {
    $topic_title = bp_get_the_topic_title();
    $title .= ' | ' . $topic_title;
    $title = str_replace( ' | Groups', '', $title );
    }
    }
    return $title;
    }
    add_filter( 'bp_page_title', 'my_page_title', 10, 2 );

    Try that.

    @r-a-y

    Keymaster

    Hey guys,

    You need to replace the pipe character with ” &##124;” (without quotes).

    [EDIT] Remove the second # character! I had to add it to this post because of the HTML character conversion.[/EDIT]

    Replace this line:

    $title = str_replace( ' | Groups', '', $title );

    with:

    $title = str_replace( ' &##124; Groups', '', $title );

    Also right after that line, add the following to remove the word “Forum”:

    $title = str_replace( ' &##124; Forum', '', $title );

    *Edit – Pastebin link added:
    http://pastebin.com/1zdN7C7K (August 24, 2010)

    @geoffm33

    Participant

    @r-a-y @boonegorges Works for me!

    How can you rearrange the order? For instance:

    Topic Title | Forum Name | Site Name

    @hydroweb

    Participant

    Yeah, my question earlier! Thanks!

    @snark

    Participant

    Thank you both, Boone and Ray, that worked perfectly! I now have the Forums title just how I wanted, and I’m sure many others will benefit from this. Great work!

    @r-a-y

    Keymaster

    @geoffm33

    Participant

    @r-a-y Brilliant, thanks!

    @snark

    Participant

    @r-a-y @boonegorges — Unfortunately, this function just broke under BP1.2-RC3:

    Fatal error: Call to undefined function: bp_has_topic_posts() in…

    Here is the complete function from you guys provided above:

    /* Custom function to re-write Forum title tags */

    function my_page_title( $title, $b ) {

    global $bp;

    if ( $bp->current_action == ‘forum’ && $bp->action_variables[0] == ‘topic’ ) {

    if ( bp_has_topic_posts() ) {

    $topic_title = bp_get_the_topic_title();

    $title .= ‘ | ‘ . $topic_title;

    $title = str_replace( ‘ | Groups’, ”, $title );

    $title = str_replace( ‘ | Forum’, ”, $title );

    }

    }

    return $title;

    }

    add_filter( ‘bp_page_title’, ‘my_page_title’, 10, 2 );

    ?>

    Any help on this greatly appreciated. Thanks.

    @snark

    Participant

    Ok, I figured it out. In the RC3 version of bp-forums-templatetags.php, it says the old function this was calling has been deprecated, and what to replace it with:

    /* DEPRECATED use bp_has_forum_topic_posts() */

    function bp_has_topic_posts() { return bp_has_forum_topic_posts( $args ); }

    function bp_forum_topic_posts() {

    global $topic_template;

    return $topic_template->user_posts();

    }

    /* DEPRECATED use bp_forum_topic_posts() */

    function bp_topic_posts() { return bp_forum_topic_posts(); }

    function bp_the_forum_topic_post() {

    global $topic_template;

    return $topic_template->the_post();

    }

    /* DEPRECATED use bp_the_forum_topic_post() */

    function bp_the_topic_post() { return bp_the_forum_topic_post(); }

    So I swapped the offending line and now have it working again using this function in my child theme functions.php file:

    /* Custom function to re-write Forum title tags */

    function my_page_title( $title, $b ) {

    global $bp;

    if ( $bp->current_action == ‘forum’ && $bp->action_variables[0] == ‘topic’ ) {

    if ( bp_has_forum_topic_posts() ) {

    $topic_title = bp_get_the_topic_title();

    $title .= ‘ | ‘ . $topic_title;

    $title = str_replace( ‘ | Groups’, ”, $title );

    $title = str_replace( ‘ | Forum’, ”, $title );

    }

    }

    return $title;

    }

    add_filter( ‘bp_page_title’, ‘my_page_title’, 10, 2 );

    ?>

    @arnonel

    Participant

    Guys, Would someone please share some code i can put in a functions.php file in my theme to change the title and description of the site as a whole?

    current if you search my site on google you get:

    “Login or Signup to make some friends! SPoint.me · Log In · Sign Up; Visit. Random Member · Random Group · Random Blog · Random Link.”

    thats not pretty! :)

    @guswill

    Participant

    @snark ‘s code doesn’t seem to work on 1.2.3. For some reason the function bp_get_the_topic_title() doesn’t seem to be returning anything. I’m a python developer by day so, my PHP debugging skills are terrible =/ .

    Does anybody know how to update it to get it working again? @r-a-y ?

    @nanchante

    Participant

    Giving this a bump: I’d really like to be able to have the page number shown in the title IF the page id > 1.

    [topic title] – page no:2

    How can I do this please?

    @islandcastaway

    Participant

    Can a dev please point out a current codex page for bp1.5 that addresses this.

    thanx

    @dannyjimmy

    Member

    I read a couple replies back that this broke; can we get an update?

    I really think this needs an update in the core; in blog posts, the title of the post always comes first. same should be true here with the topic title.

    @raphadko

    Participant

    I got this guys, here is the code I ended up with..

    Code:
    function my_page_title( $title) {
    global $bp;

    if ( $bp->current_action == ‘forum’ && $bp->action_variables[0] == ‘topic’ ) {
    return bp_get_the_topic_title(). ‘ | ‘ . bp_current_action() . ‘ ‘. bp_get_current_group_name(); ;
    }
    else
    return $title;
    }
    add_filter( ‘bp_modify_page_title’, ‘my_page_title’, 10);

Viewing 20 replies - 1 through 20 (of 20 total)
  • The topic ‘Editing Group and Forum page title tags’ is closed to new replies.
Skip to toolbar