• Resolved maximusnyc

    (@maximusnyc)


    In Singl’s header.php file, I see the following code:

    <title><?php wp_title( '|', true, 'right' ); ?></title>

    The result that displays in my browser tab is this:

    PAGE_TITLE | SITE_TITLE

    What I actually want is this:

    SITE_TITLE | PAGE_TITLE

    The WP Codex documentation for the $wp_title function explains how to move the separator to the left or right of the post/page title. It also says this:

    By default, the separator is displayed before the page title, so that the blog title will be before the page title.

    But I can’t get that result. When I modify the code in Singl’s header.php to read as follows:

    <title><?php wp_title(); ?></title>

    …I should be getting that default behavior… but what I see in my browser tab is this:

    ? PAGE_TITLESITE_TITLE

    …just like that, with no space between the page and site titles.

    The Codex entry on $wp_title says that the default is for the site title to go on the left — and that’s what I want. So why can’t I make that happen? Is there some code somewhere in the Singl theme that is overriding this default? If so, how can I change it?

    P.S. No need to explain that what I’m trying to do is not considered “best practice”… I’m aware of that. It’s just the style I prefer for my site.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Kathryn Presner

    (@zoonini)

    Hi there – a quick way to get the result you want would be to use a plugin like WordPress SEO by Yoast, which lets you customize the title output. Would that work for your needs?

    Thread Starter maximusnyc

    (@maximusnyc)

    Hi Kathryn,

    Thanks for the suggestion. That plugin looks like it might be overkill for my needs, but I’ll research it some more.

    I guess the implication of your answer is that what I’m looking to do cannot be done without a plugin: displaying the page title followed by the site title is apparently hardwired into WordPress (despite what the Codex page I linked to above seems to say).

    Moderator Kathryn Presner

    (@zoonini)

    Singl’s title function is found in inc/extras.php:

    function singl_wp_title( $title, $sep ) {
    	global $page, $paged;
    
    	if ( is_feed() ) {
    		return $title;
    	}
    
    	// Add the blog name
    	$title .= get_bloginfo( 'name' );
    
    	// Add the blog description for the home/front page.
    	$site_description = get_bloginfo( 'description', 'display' );
    	if ( $site_description && ( is_home() || is_front_page() ) ) {
    		$title .= " $sep $site_description";
    	}
    
    	// Add a page number if necessary:
    	if ( $paged >= 2 || $page >= 2 ) {
    		$title .= " $sep " . sprintf( __( 'Page %s', 'singl' ), max( $paged, $page ) );
    	}
    
    	return $title;
    }
    add_filter( 'wp_title', 'singl_wp_title', 10, 2 );

    Since this function isn’t pluggable – isn’t meant to be modified by overriding in a child theme – I think you’d need add a new filter function in a child theme, which is a little bit complicated. That’s why I suggested the plugin, it’s generally easier, unless you’re able to write your own PHP function. But you could try either route, depending what you’re most comfortable with.

    Thread Starter maximusnyc

    (@maximusnyc)

    Ah, thanks for the additional info! That’s helpful. I do have a smidgen of PHP experience; I may try writing my own function.

    Moderator Kathryn Presner

    (@zoonini)

    Excellent! If you get something working, do feel free to post it here in case it helps others in the future. ??

    Thread Starter maximusnyc

    (@maximusnyc)

    Sure, will do!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Why can't I put site title before page title in browser tab?’ is closed to new replies.