Change page title to "SiteTitle" | "PageTitle"
-
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?
-
Look into the
header.phpand see how it implementswp_title(), also look infunctions.phpsee if there is a function filtering the output ofwp_title()
http://codex.wordpress.org/Function_Reference/wp_titleOn 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.
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.
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.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 filterwp_title(), so we should not useis_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 itfunctions.php, at the very top put this in<?phpand 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' );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 defaultwp_title()already gives site name.And use
is_page() && ! is_front_page()instead ofis_page()So now we have this.
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() && !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; }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 ๐
Noted! Hahah!
The topic ‘Change page title to "SiteTitle" | "PageTitle"’ is closed to new replies.