BuddyBoss Home – Web Support Forums Themes Boss. theme Duplicate sitename caused by custom filter

Viewing 2 posts - 1 through 2 (of 2 total)
  • Question

    #56293
    @keen

    Hi,

    Someone posted a while ago (here) about duplicate site titles and his solution was to delete the site title from within the Yoast SEO plugin settings (not ideal).

    After this has happened to me on a different theme, I went in search of a filter and found this in theme-functions.php:

    /**
     * Creates a nicely formatted and more specific title element text
     * for output in head of document, based on current view.
     *
     * @since Boss 1.0.0
     *
     * @param string $title Default title text for current view.
     * @param string $sep Optional separator.
     * @return string Filtered title.
     */
    function buddyboss_wp_title( $title, $sep ) {
    	global $paged, $page;
    
    	if ( is_feed() )
    		return $title;
    
    	// Add the site name.
    	$title .= get_bloginfo( 'name' );
    
    	// Add the site description for the home/front page.
    	$site_description	 = get_bloginfo( 'description', 'display' );
    	if ( $site_description && ( is_home() || is_front_page() ) )
    		$title				 = "$title $sep $site_description";
    
    	// Add a page number if necessary.
    	if ( $paged >= 2 || $page >= 2 )
    		$title = "$title $sep " . sprintf( __( 'Page %s', 'boss' ), max( $paged, $page ) );
    
    	return $title;
    }
    
    add_filter( 'wp_title', 'buddyboss_wp_title', 20, 2 );

    If I prevent this filter from firing, I don’t get a duplicate site title issue.

    I’ve used this code in my child theme functions and it is working:

    function remove_page_title_filter() {
        remove_filter( 'wp_title', 'buddyboss_wp_title', 20, 2 );
    }
    add_action( 'init', 'remove_page_title_filter', 20, 2 );

    Can you think of a better way to handle this?

    Thanks

    Answers

    #56296
    @keen

    EDIT:

    function remove_page_title_filter() {
        remove_filter( 'wp_title', 'buddyboss_wp_title', 20, 2 );
    }
    add_action( 'wp_loaded', 'remove_page_title_filter', 20, 2 );
Viewing 2 posts - 1 through 2 (of 2 total)
  • The question ‘Duplicate sitename caused by custom filter’ is closed to new replies.