WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] PHP for adding page title - problem with title of static front page (6 posts)

  1. cokeyblokey
    Member
    Posted 2 years ago #

    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

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Try replacing:

    else {
    	bloginfo('name'); }

    with:

    elseif (is_page()) {
    	wp_title('');
            echo ' - ';
    	bloginfo('name');
    }
    else {
    	bloginfo('name'); }
  3. cokeyblokey
    Member
    Posted 2 years ago #

    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'

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    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; }
    ?>
  5. cokeyblokey
    Member
    Posted 2 years ago #

    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

  6. lettergrade
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic