mgason
Member
Posted 5 months ago #
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>
Probably safer to use if () { } elseif {} elseif {}
rather than just a bunch of if statements.
More docs: http://php.net/manual/en/control-structures.elseif.php
That way, once it finds a match, it will stop looking for another match.
mgason
Member
Posted 5 months ago #
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().
http://codex.wordpress.org/Conditional_Tags
mgason
Member
Posted 5 months ago #
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'); ?> | <?php bloginfo('description'); ?>
} elseif ( is_search() )
<?php bloginfo('name'); ?> | Search Results
} elseif ( is_author() ) {
<?php bloginfo('name'); ?> | Author Archives
} elseif ( is_single() ) {
<?php wp_title(''); ?> | <?php bloginfo('name'); ?>
} elseif ( is_page() ) { ?>
<?php bloginfo('name'); ?> | <?php wp_title(''); ?>
} elseif ( is_category() ) {
<?php bloginfo('name'); ?> | Archive | <?php single_cat_title(); ?>
} elseif ( is_month() )
<?php bloginfo('name'); ?> | Archive | <?php the_time('F'); ?>
} elseif (function_exists('is_tag'))
if ( is_tag() ) {
<?php bloginfo('name'); ?> | Tag Archive | <?php single_tag_title("", true); }?>
} ?>