Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding single topic title into meta title for SEO


  • ilovemetrics
    Participant

    @ilovemetrics

    Hoping someone has solved for this…

    I’m trying to make sure that all single topic pages are unique for SEO purposes. Currently, topics simply have the format “Forum – [Forum Name] – [Site Name]”. I want to prepend the topic so that the meta title tag format is “[Topic Name] – [Forum Name] – [Site Name]”.

    I do not want to use Yoast or any other plugin, as this should be a pretty simple change.

    The problem I am having is two fold:

    1. In functions.php, I am unable to use anything like is_bbpress() or bbp_is_single_topic() to tell if I am on a specific page.
    2. I am unable to get the bbPress topic title ahead of the pre_get_document_title() function so that I can prepend it into the meta header.

    Any help would be greatly appreciated. This is for a WordPress/BuddyPress/bbPress integration.

    Thanks in advance

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

  • Stephen Edgar
    Keymaster

    @netweb

    Have you seen bbp_new_topic_pre_title() in includes/topics/functions.php ?

    (There’s also bbp_new_forum_pre_title() in includes/forums/functions.php)


    ilovemetrics
    Participant

    @ilovemetrics

    Hi,

    Thanks for the response. I’m not following how this would solve the problem, though. From what I can see of that filter, I need to pass in the topic title into this function, but I can’t get the topic title in functions.php early enough.

    Here’s the function (in functions.php) I’ve created to modify the title in other ways needed (replace “Forum” with “Investment Groups” and replace mdash; with a hyphen as the main separator). This is where I’d want to incorporate the logic:

    function theme_mod_title() {
        	add_filter('document_title_separator', function() {
            	return '$%';
        	});
        	remove_filter('pre_get_document_title', 'theme_mod_title');
        	$find = array(
    			'/ \$% /', 
    			'/^Forums/'
    		);
        	$replace = array(
    			' - ', 
    			'Investment Groups'
    		);
        	$title = wp_get_document_title();
    
    	// filter the title    
        	$ftitle = preg_replace($find, $replace, $title);
    
            NOT SURE HOW TO ACCOMPLISH THIS, BUT LOGIC NEEDED IS
    	//if (on bbpress topic page){
    		$ftitle = bbpress topic title . ' - ' . $ftitle;
    	//}
    
    	return $ftitle;
    }
    add_filter('pre_get_document_title', 'theme_mod_title');

    The bbPress part is where I’m stuck. I’m not sure how to actually get the topic title early enough to pass it into the document title. This seems to be the only place I can actually set any new meta title tag logic, but I can’t tap into anything bbPress this early in the process.

    Thanks again


    ilovemetrics
    Participant

    @ilovemetrics

    Thinking about this in another way, would you be able to point me in the direction of where the “Forum” and “Group Name” portions of the meta title are being set?

    Current output to the title tag is: “<title>Forum – [Group Name] – Site Name</title>”. For my purposes, I could either tap into whatever function is setting the “Forum” or “Group Name” to prepend the topic name.

    Thanks again


    ilovemetrics
    Participant

    @ilovemetrics

    Hi,

    Hate to be a bother, and I can imagine you get a million questions, but this is the only thing holding me back from launching a site I’ve been working on for 9 months, so I’m pulling my hair out over here. Any help would be appreciated. It seems like no one has been able to solve for this, given my extensive Googling on the subject.

    Yoast and any other SEO plugins aren’t compatible and just output blank, so that is not an option. Is there any way at all to access the topic title to add to the page title on bbPress topic pages?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar