• Resolved LeClair

    (@joshaleclairgmailcom)


    Last step before I can set the site live! I’m struggling with the <head> section of the site. On all of my pages it simply says the page name as the browser title (Contact, Media, etc.) instead of the Site Title and then the page name. Any suggestions?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Look into the header.php and see how it implements wp_title(), also look in functions.php see if there is a function filtering the output of wp_title()
    https://codex.www.ads-software.com/Function_Reference/wp_title

    On all of my pages it simply says the page name..instead of the Site Title and then the page name.

    Yours is only page name, most WP themes would have “Page name : Site title” on the page, it’s good for SEO that way.

    Thread Starter LeClair

    (@joshaleclairgmailcom)

    Yeah, I’m trying to set it up like that. Unfortunately, right now my header.php looks like this…

    > >
    < id="site-title">  > < id="site-description">>
    
    Show Navigation Hide Navigation 'primary_nav' ) ); ?>

    I’m using the Pinboard theme. Curious.

    Thread Starter LeClair

    (@joshaleclairgmailcom)

    And in functions.php the wp_title line looks like this:

    add_filter( 'wp_title', 'pinboard_doc_title' );

    Neither of these look like what the wp_title function reference is talking about. Any suggestions?

    That function is pluggable, notice it’s in

    if ( ! function_exists( 'pinboard_doc_title' ) )

    The theme’s author did that so child theme could override this function easily by just decare the same function name in child’s functions.php, and parent will not load it again.

    So you could just sneak in is_page() and append it with site name.

    Thread Starter LeClair

    (@joshaleclairgmailcom)

    So this is what I came up with and is not doing the trick, not because what you said isn’t working, but because I’m not fully up to speed with my CSS yet…

    is_page() {
      <title><?php bloginfo('name'); ?><?php wp_title('|'); ?></title>
    }

    Can you point me in the right direction? Thanks for helping me out!!

    All of this has nothing to do with CSS, it’s PHP.

    Your theme has this function pinboard_doc_title() to filter wp_title(), so we should not use is_page() directly in the template like that, because the output will get filtered anyway.

    So we have to either filter the output of that function again ( make changes to it ), or override it. In this case we should override it because that function is a pluggable one.

    So in your child theme’s functions.php, just copy over this function exactly from parent’s and start making change in there.

    In your child theme’s folder, if you already got a functions.php, just put the code in below. If you haven’t got one yet, just create a blank file and name it functions.php, at the very top put this in <?php and do not put the closing ?> in the bottom.

    function pinboard_doc_title( $doc_title ) {
    	global $page, $paged;
    	$doc_title = str_replace( '?', '', $doc_title );
    	$site_description = get_bloginfo( 'description', 'display' );
    	$separator = '#124';
    	if ( is_singular() ) {
    		if( is_page() )
    			$doc_title .= ' &' . $separator . '; ';
    			$doc_title .= get_bloginfo( 'name' );
    		if( is_front_page() )
    			$doc_title .=  get_the_title();
    		if ( $paged >= 2 || $page >= 2 )
    			$doc_title .=  ', ' . __( 'Page', 'pinboard' ) . ' ' . max( $paged, $page );
    	} else {
    		if( ! is_home() )
    			$doc_title .= ' &' . $separator . '; ';
    			$doc_title .= get_bloginfo( 'name' );
    		if ( $paged >= 2 || $page >= 2 )
    			$doc_title .=  ', ' . __( 'Page', 'pinboard' ) . ' ' . max( $paged, $page );
    	}
    	if ( ( is_home() ) && $site_description )
    		$doc_title .= ' &' . $separator . '; ' . $site_description;
    	return $doc_title;
    }

    The function above is the same exact one from the parent’s with 3 lines added, you will notice the is_page() block here.

    if( is_page() )
    	$doc_title .= ' &' . $separator . '; ';
    	$doc_title .= get_bloginfo( 'name' );

    Now you will get Page Title | Site Title on page.

    if you want the same thing for post to, just put in OR ( || ) like this

    if( is_page() || is_single() )
    	$doc_title .= ' &' . $separator . '; ';
    	$doc_title .= get_bloginfo( 'name' );
    Thread Starter LeClair

    (@joshaleclairgmailcom)

    Wow! Worked like a charm, besides the first page, where it reads |JoshuLeClair.caHome

    This is really helpful. Thank you for taking the time to explain how this all works instead of just throwing code I can’t hope to begin to understand at me.

    besides the first page, where it reads |JoshuLeClair.caHome

    That’s wrong, so we have to fix it.

    Delete the is_front_page() block, we don’t need that because it seems the default wp_title() already gives site name.

    And use is_page() && ! is_front_page() instead of is_page()

    So now we have this.

    function pinboard_doc_title( $doc_title ) {
    	global $page, $paged;
    	$doc_title = str_replace( '&raquo;', '', $doc_title );
    	$site_description = get_bloginfo( 'description', 'display' );
    	$separator = '#124';
    	if ( is_singular() ) {
    		if( ( is_page() && !is_front_page() ) || is_single() )
    			$doc_title .= ' &' . $separator . '; ';
    			$doc_title .= get_bloginfo( 'name' );
    		if ( $paged >= 2 || $page >= 2 )
    			$doc_title .=  ', ' . __( 'Page', 'pinboard' ) . ' ' . max( $paged, $page );
    	} else {
    		if( ! is_home() )
    			$doc_title .= ' &' . $separator . '; ';
    		$doc_title .= get_bloginfo( 'name' );
    		if ( $paged >= 2 || $page >= 2 )
    			$doc_title .=  ', ' . __( 'Page', 'pinboard' ) . ' ' . max( $paged, $page );
    	}
    	if ( ( is_home() ) && $site_description )
    		$doc_title .= ' &' . $separator . '; ' . $site_description;
    	return $doc_title;
    }
    Thread Starter LeClair

    (@joshaleclairgmailcom)

    Amazing – thanks so much for all your help!

    Any “For Dummies” guides you’d recommend to help get me further in this direction? =)

    I’m looking for one of that for myself too ??

    Thread Starter LeClair

    (@joshaleclairgmailcom)

    Noted! Hahah!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Change page title to "SiteTitle" | "PageTitle"’ is closed to new replies.