• Resolved cokeyblokey

    (@cokeyblokey)


    I’m having a problem getting my ‘static front page’ title to display correctly. My theme (html5 reset) has the following code in header.php:

    <title>
    <?php
    	if (function_exists('is_tag') && is_tag()) {
    		single_tag_title("Tag Archive for &quot;"); echo '&quot; - '; }
    	elseif (is_archive()) {
    		  wp_title(''); echo ' Archive - '; }
    	elseif (is_search()) {
    		   echo 'Search for &quot;'.wp_specialchars($s).'&quot; - '; }
    	elseif (!(is_404()) && (is_single()) || (is_page())) {
    		   wp_title(''); echo ' - '; }
    	elseif (is_404()) {
    		   echo 'Not Found - '; }
    	if (is_home() && is_front_page()) {
    		bloginfo('name'); echo ' - '; bloginfo('description'); }
    	else {
    		   bloginfo('name'); }
    	if ($paged>1) {
    	echo ' - page '. $paged; }
    ?>
    </title>

    If I use the WP default setting of ‘latest posts’ as my front page then I get the desired title format for the front page: ‘name – description’

    If I change to use a static page as front page then I end up with the following title format for the front page: ‘(blank) – name’ – where (blank) is just completely empty.

    Can somebody please help and advise as to what I nead to add to the3 above for it to display the title of the static front page as: ‘name – description’

    TIA
    Marc

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try replacing:

    else {
    	bloginfo('name'); }

    with:

    elseif (is_page()) {
    	wp_title('');
            echo ' - ';
    	bloginfo('name');
    }
    else {
    	bloginfo('name'); }
    Thread Starter cokeyblokey

    (@cokeyblokey)

    Sorry esmi, bit of a confusion with my code – my fault as I posted one line slightly differently to what I’m currently using.

    This line:

    if (is_home() && is_front_page()) {

    is actually this:

    if (is_home()) {

    so the full code is:

    <title>
    <?php
    	if (function_exists('is_tag') && is_tag()) {
    		single_tag_title("Tag Archive for ""); echo '" - '; }
    	elseif (is_archive()) {
    		  wp_title(''); echo ' Archive - '; }
    	elseif (is_search()) {
    		   echo 'Search for "'.wp_specialchars($s).'" - '; }
    	elseif (!(is_404()) && (is_single()) || (is_page())) {
    		   wp_title(''); echo ' - '; }
    	elseif (is_404()) {
    		   echo 'Not Found - '; }
    	if (is_home()) {
    		bloginfo('name'); echo ' - '; bloginfo('description'); }
    	else {
    		   bloginfo('name'); }
    	if ($paged>1) {
    	echo ' - page '. $paged; }
    ?>
    </title>

    I have tried your suggestion on both versions but all I get for the title is: ‘- – name’

    Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this:

    <?php
    	if (function_exists('is_tag') && is_tag()) {
    		single_tag_title("Tag Archive for "); echo '" - '; }
    	elseif (is_archive()) {
    		  wp_title(''); echo ' Archive - '; }
    	elseif (is_search()) {
    		   echo 'Search for "'.wp_specialchars($s).'" - '; }
    	elseif (!(is_404()) && (is_single()) || (is_page() && !is_front_page())) {
    		   wp_title(''); echo ' - '; }
    	elseif (is_404()) {
    		   echo 'Not Found - '; }
    	if (is_home() || is_front_page()) {
    		bloginfo('name'); echo ' - '; bloginfo('description'); }
    	else {
    		   bloginfo('name'); }
    	if ($paged>1) {
    	echo ' - page '. $paged; }
    ?>

    Thread Starter cokeyblokey

    (@cokeyblokey)

    Thank you keesiemeijer, that has done the trick!
    Really appreciate your help, and esmi’s help too.
    I will study this so I can learn exactly why it has worked.
    Marc

    Just wanted to pipe in and say this helped me too!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘PHP for adding page title – problem with title of static front page’ is closed to new replies.