Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: BuddyPress 2.2.1 incompatible with Yoast SEO, botched page titles

@megabait12

Participant

Try this one


/**
 * Fix wpseo title
 */
add_filter('wpseo_title', 'buddypress_wpseo_title');

function buddypress_wpseo_title($title) {
    $wpseo = WPSEO_Frontend::get_instance();
    $separator = $wpseo->options['separator'];

    $separator_options = array(
        'sc-dash' => '-',
        'sc-ndash' => '–',
        'sc-mdash' => '—',
        'sc-middot' => '·',
        'sc-bull' => '•',
        'sc-star' => '*',
        'sc-smstar' => '⋆',
        'sc-pipe' => '|',
        'sc-tilde' => '~',
        'sc-laquo' => '«',
        'sc-raquo' => '»',
        'sc-lt' => '<',
        'sc-gt' => '>',
    );

    if (array_key_exists($separator, $separator_options)) {
        $separator = $separator_options[$separator];
    }
    $bp = buddypress();
    if (bp_is_user()) {
        $title = bp_get_displayed_user_fullname() . ' | ' . ucfirst($bp->current_component);
    } elseif (bp_is_group()) {
        $title = bp_get_current_group_name() . ' | ' . $bp->bp_options_nav[$bp->groups->current_group->slug][bp_current_action()]['name'];
    }

    return $title . ' ' . $separator . ' ' . get_bloginfo();
}
Skip to toolbar