• I have code to add blog name and tagline to my site title in the theme. The home page title is effected by the code in the is_page line, but not by the code in the is_home line. It does not matter what i put in the home line, nothing works.
    what is wrong?
    Also I would like to add the tagline to the blog page, which is a page named blog and assigned for posts in Settings/Reading static page.

    <!-- Custom Title Setup -->
    <title>
    <?php //storefront_title(); ?>
    <?php if ( is_home() ) { ?><?php bloginfo('name'); ?>?|?<?php bloginfo('description'); ?><?php } ?>
    <?php if ( is_search() ) { ?><?php bloginfo('name'); ?>?|?Search Results<?php } ?>
    <?php if ( is_author() ) { ?><?php bloginfo('name'); ?>?|?Author Archives<?php } ?>
    <?php if ( is_single() ) { ?><?php wp_title(''); ?>?|?<?php bloginfo('name'); ?><?php } ?>
    <?php if ( is_page() ) { ?><?php bloginfo('name'); ?>?|?<?php wp_title(''); ?><?php } ?>
    <?php if ( is_category() ) { ?><?php bloginfo('name'); ?>?|?Archive?|?<?php single_cat_title(); ?><?php } ?>
    <?php if ( is_month() ) { ?><?php bloginfo('name'); ?>?|?Archive?|?<?php the_time('F'); ?><?php } ?>
    <?php if (function_exists('is_tag')) { if ( is_tag() ) { ?><?php bloginfo('name'); ?>?|?Tag Archive?|?<?php  single_tag_title("", true); } } ?>
    </title>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Probably safer to use if () { } elseif {} elseif {}

    rather than just a bunch of if statements.

    More docs: https://php.net/manual/en/control-structures.elseif.php

    That way, once it finds a match, it will stop looking for another match.

    Thread Starter mgason

    (@mgason)

    Thanks that is a good point I will do that.
    Do you see anything wrong with that first line is_home?
    Even when I remove all the other if statements and leave just that one it does not work. even if I just put plain text in it.

    As I said if I delete all and leave page it works for home.

    If your home page is a static one (as opposed to a list of your recent posts), you need to use is_front_page().
    https://codex.www.ads-software.com/Conditional_Tags

    Thread Starter mgason

    (@mgason)

    Hi,
    I have been trying to turn that block into a if else statement without luck. My syntax seems goofy and I am not a php expert. Can anyone straighten me out?

    <?php //storefront_title(); ?>
    <?php
    if ( is_front_page() ) {
    	 <?php bloginfo('name'); ?>
    } elseif ( is_home() ) {
    	<?php bloginfo('name'); ?>&nbsp;|&nbsp;<?php bloginfo('description'); ?>
    } elseif ( is_search() )
    	<?php bloginfo('name'); ?>&nbsp;|&nbsp;Search Results
    } elseif ( is_author() ) {
    	<?php bloginfo('name'); ?>&nbsp;|&nbsp;Author Archives
    } elseif ( is_single() ) {
    	<?php wp_title(''); ?>&nbsp;|&nbsp;<?php bloginfo('name'); ?>
    } elseif ( is_page() ) { ?>
    	<?php bloginfo('name'); ?>&nbsp;|&nbsp;<?php wp_title(''); ?>
    } elseif ( is_category() ) {
    	<?php bloginfo('name'); ?>&nbsp;|&nbsp;Archive&nbsp;|&nbsp;<?php single_cat_title(); ?>
    } elseif ( is_month() )
    	<?php bloginfo('name'); ?>&nbsp;|&nbsp;Archive&nbsp;|&nbsp;<?php the_time('F'); ?>
    } elseif (function_exists('is_tag'))
    	if ( is_tag() ) {
    		<?php bloginfo('name'); ?>&nbsp;|&nbsp;Tag Archive&nbsp;|&nbsp;<?php  single_tag_title("", true); }?>
          } ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘page title tagline code not working for home?’ is closed to new replies.