BuddyDev

Making WordPress SEO plugin compatible with BuddyPress Part 2

This post has been updated for WordPress Seo 3.0+. For title fix, all you need is the code from step 1

I hope that you might have read my previous post on making WordPress SEO plugin compatible with BuddyPress. If not, please do read the post here.

Based on the suggestions and feedback, I have updated the code to be more meaningful. In the end of this post, I am going to propose a new strategy too, and the future enhancement will depend on your suggestions.

My special thanks to Martin, Marc, Justina, Giorgos and all of you who provided your valuable feedback on my previous post.

So, what this code is all about:-

  • It fixes canonical url issue on BuddyPress Components pages
  • It provides better support for better group forum meta description when using bbpress plugin for group forums
  • It fixes the title issue when flushing is enabled in WordPress SEO plugin
  • And last, It also supports our very own BuddyBlog single post meta description in more meaningful way

Step1:- Fixing Titles for BuddyPress generated pages

Step2: Fix the canonical URL

The WordPress SEO plugin uses url of directory page for all the component pages. We need these to be more specific.

There is another issue, In WordPress, there is no definite way to know the absolute url of current page( and by page, I did not mean WordPress pages). add_query_arg Β function does provide relative url if we pass false parameters( May discuss some other day). So, I used a code snippet from WebCheetSheet and modified it for our purpose. Here is the code to get current page url.

And then, hooked our function to ‘wpseo_canonical’ filter as below.

That’s it for fixing the canonical url.

Step3:- Better meta descriptions

I am just revisiting the code from my previous post. This code is much better and supports better meta for group forums and buddyblog.

Future:-

Will you like to have an easy metabox in your post edit screen ( say members directory page ) Β that allows you to easily enter meta for single user pages ( like friends, groups, etc )? I am thinking of writing a base plugin which can be used by any plugin to add their own specific meta boxes and then, we can fetch these meta boxes in one go by passing the component, action, action variables(It will save all the complex code above) . Do you think that is a good idea? If yes, what are the things you would like to enter on that page?

Please do share your thoughts.

PS: Please do visit again for the next two free components: Signup Avatar plugin tomorrow and next day for BuddyDocs theme Β  πŸ™‚

54 Responses to Making WordPress SEO plugin compatible with BuddyPress Part 2

  • Way cool – just giving it a shake down now (while setting up some split tests hahaha)
    Looking real good though, Brajesh

    • Thank you Martin. You were the one who motivated me to complete this part πŸ™‚

      • Pleasure mate.
        I actually joined up here and left another comment which is waiting in the moderation Q too.
        Also left you some feedback as well as another message.

        • Hi Martin,
          Thank you for supporting us and helping with the feedback. I am sorry, I was not looking at comments for a couple weeks properly, so might have missed your comment. Going to look on it today πŸ™‚

  • Thats the real job!!. Thanks. Turn this into a plugin, name it ” The ultimate fix for having BP work with WP-SEO” and a million downloads wont be a problem πŸ™‚

    So it fixes canonicals where the issue I had with single images urls in BP gallery is no more.
    Now BP gallery images have their own urls and can be shared among social networks and others.

    Still I have a problem with group forum titles as they are not generated (global forums works fine) and member titles . Still are not generated. Am I doing something wrong?

    I pasted the code in BP-custom.php and I use the recommended by WP-SEO title instead of
    I hope code above is not stripped out.

    Over the future , If the metabox solution eliminates the above custom code, then I’m in favour of it. It sounds nice if you can enter a custom meta description,title, etc, at a BP page and that can be used by other plugins.
    On the other hand you might also wont to consider writing a BP SEO plugin as there is nothing decent out there.

    • Hi Giorgos,
      Thank you for the generous comment πŸ™‚
      Hoping for something better in future again. For now, as we have been discussing in forum, I hope that the thing about description is clear.

      About the title, I missed that thing in my update. It does not take seo title, It takes title generated by BuddyPress. I will update this tutorial again this weekend with the seo title feature πŸ™‚

      I am not an SEO expert, I just know few things about it, that’s why I never dived into writing SEO plugin. I still hope that we can have some basic sort of plugin for sure πŸ™‚

      • Wonderful work Brajesh. Thank you. I look forward to your update this weekend too.

        This fix may help some people. For my site, to get the BP auto-generated titles to show for BP Group Forums, I need to replace the first line of code above:
        i.e.:
        add_action( ‘template_redirect’, ‘bpdev_wpseo_title_fix_for_bp’ );

        with:
        add_action( ‘wp_loaded’, ‘bpdev_wpseo_title_fix_for_bp’ );
        which is the previous first line of code from https://buddydev.com/buddypress/making-wordpress-seo-plugin-compatible-with-buddypress/

        For some reason the code using the action hook ‘template_redirect’ doesn’t work for my site. I’m putting the code in the functions.php of my child theme of BP Default. Any ideas why Brajesh?

        • Didn’t work for me πŸ™
          Neither option produces Titles for Group Forums

      • Hi Brajesh,

        Is this still a live project for you? Is your update you mention above coming any time soon?

  • Hi thanks for the update,
    Im having the Same problem, the group forums are still not getting custom titles,
    ive added the code to functions in the child theme

    • Can’t read the language myself but I hope it helps Brajesh put some added polish to his fine work, so far πŸ™‚

  • Thank you so much for this. Just to be clear, this, part 2 supplants what you wrote in part 1? so we should implement the code here and ignore part 1? just want to make sure that’s clear.

    Thanks again.

    • Hi Wilson,
      It is a replacement of part one. Just ignore part 1 codes.

      • Thanks. Sorry for the n00b question but exactly where should one cut/paste the 4 code snippets? inside wp? buddypress? the seo plugin? can you please be specific?

        oh and a small correction, it is “webcheatsheet” not “webcheetsheet”

        πŸ™‚

        • Thank You Wilson for asking.
          Please put it in your theme’s functions.php or bp-custom.php in your plugins directory.

  • Yeah, much the same as @giorgos the Group Forum topic titles aren’t being used unfortunately. This is a huge start in fixing the most popular SEO plugin to work with the best Social WP plugin so kudos to @brajesh

    • HI Martin,
      The problem was I did not use seo title for forum/forum posts. I just let BuddyPress generate them. I will have another update to handle that case soon πŸ™‚

  • Great job @sbrajesh!

  • Thanks to this approach I can now remove the many if statements I had in my header.php file around the tag.

  • My post should read title tag but using angle brackets stripped out the word title πŸ™‚

  • Adding the step 1 solution leave my titles completely empty, Any idea of solving this?

    • Please try the fix that I mentioned in my 12 Sept comment above. It worked for me. I’d be interested to hear if it works for you too….and also to hear what Brajesh has to say about it.

  • Thanks Marc, I had already tried it. It wont make any difference. Title remained empty

  • Has there been any updates to this yet ?

  • the drawback is also that google webmaster tools starts showing me html issues with duplicated titles and descriptions.

  • Hi Brajesh

    The meta titles generated by BP aren’t unique enough. Can we filter the titles BP generates in the same way you’ve filtered the meta description? If so, do you know the filter name I can use?

    Thanks again for this useful snippet!

  • After using your filter to stop WP SEO title generation on BP pages I’ve now come up with a way to filter the titles BP generates to make them more suited to my site Is this how you would do it? Hoping this code paste works….

    // modify meta titles generated by BP pages
    function modify_bp_meta_titles( $title, $title, $sep, $seplocation ) {
    if ( bp_is_directory() ) {
    $title = sprintf( __( ‘%s directory’, ‘buddypress’ ), bp_get_name_from_root_slug() );
    }
    return $title;
    }
    add_filter( ‘bp_modify_page_title’, ‘modify_bp_meta_titles’, 10, 4 );

  • Humm, although my filter is working for the members directory, when I change it to target buddyblog page titles it doesn’t work? any help would be appreciated πŸ™‚

    e.g.

    if ( bp_is_buddyblog_component() ) {
    $title = bp_get_displayed_user_fullname() . ‘ – ‘ . get_bloginfo( ‘name’ );
    }

  • Apologies for all the posts on this thread, done 4 already today. Just wanted to let you know I solved the issue. I just went into the BuddyBlog code and see you already have a function to filter the BP title ‘buddyblog_modify_page_title’

    I just had to give my function a priority larger than 20 for it to work how I needed it to πŸ™‚

  • Hi Brajesh,

    Just so we all know what to expect, please could you tell us if this is still a live project for you.

    The reason I ask, is that you mentioned above that you were planning to update this code in the weekend in the middle of September. So I, and I guess many others too, would be pleased to hear your plans please. Many thanks.

  • Has anyone found a solution because marks not had a reply so it looks like Brajesh has stopped working on this,

  • Any news from anyone on this? It would be very sad if progress has stopped on this. Please post if you have any suggestions on what we do now.

  • Hi Brajesh,

    Is this code still interesting to use since all the new versions of Yoast Seo (for example) ? Does buddypress still lack a lot in SEO ?

    THx for your time and aweosme site !

    • Hi Evrard,
      It is not tested with the Yoast SEO 3.0+

      Will do the testing and let you know in a day or two.

      Thank you
      Brajesh

      • Can’t thank you enough for your time and support ! Thx a lot ! looking forward to read your answer on this point πŸ™‚

  • Hi @Brajesh, any news on this point ?
    Thx a lot.

    • Hi,
      Thank you for the follow up. The title fix will not work with Yoast Seo 3.0+. There is an easy solution though. I will post tonight or early tomorrow as a blog post and will link here.

      Thank you
      Brajesh

      • Hey @Brajesh Have you found a solution to make it compatible with the current version of Yoast??

        Thanks

        • Hi Dale,
          Apologies for the delayed reply. It was a simple fix but I forgot to update the post. Have updated it now.

          Thank you
          Brajesh

      • Hi @Brajesh, any news on this point ?
        Am also waiting for this fix. Thanks.

        • Apologies for the delayed reply, Have updated the post to fix the title issue.

      • Hey Brajesh,

        Were you ever able to figure out that easy solution? I notice when I go to my profile on this website the title is correct. I am trying to make Yoast SEO (3.4.2) work with my current BuddyPress (2.6.2) setup.

        I am also willing to pay for it as a plugin if you decide to put it in your repository.

        Thanks

        • Hi Core,
          I have updated the post. Please see the step1 for the fix on title.

          Thank you
          Brajesh

  • Thank you! This helped so much.

    • You are most welcome πŸ™‚

      • Quick question… is there a way to exclude one page by it’s id from using this? I would like my “Groups” page to not have it’s title and meta overwritten.

      • Hi Brajesh,

        this seems to be the only useful working solution, great work, thanks a lot, even the meta hack makes sense.

        i just noticed one thing when i checked the meta data, if you use YoastΒ΄s Social Meta Cards, it seems that the title meta is not modified, maybe you can check this in your next version?
        tnx, Eric

        • Hi Eric,
          Thank you for the comment.
          I am glad it helped.

          I was not using the social meta cards. Will certainly look into it for the future update.

  • Cant get this to work, can I not just pay you to fix my site, BuddyPress is driving me nuts!!

    • Sorry about the delayed reply. I hope you have got it resolved by now. If not, Please post in our forum and we will assist.

  • Hi!
    Thanks for good solution.
    You have one error.
    You should check that topic, forum or post description is not empty.
    Example:

    $tmp_forum_desc = WPSEO_Meta::get_value( 'metadesc', $post_id );
    if ( $tmp_forum_desc ) {
    $desc = $tmp_forum_desc;
    }

Subscribe