I am creating wordpress theme and want to get and display dynamic content for my theme Title Tag and Meta Description Tag.
For Title Tag Content: I want Title For Meta Description: I want Bloginfo('description');
When I used following codes for my title it works fine:
<?php if( is_home() || is_front_page() ): ?>
<title><?php bloginfo('name'); echo ' | '; bloginfo('description'); ?></title>
<?php elseif ( is_single() || is_page() ): ?>
<title><?php wp_title('|', true, 'right'); bloginfo('name'); ?></title>
<?php elseif ( is_category() ): ?>
<title><?php single_cat_title(); echo ' | '; bloginfo('name'); ?></title>
<?php elseif ( is_tag() ): ?>
<title><?php single_tag_title(); echo ' | '; bloginfo('name'); ?></title>
<?php elseif ( is_day() ): ?>
<title><?php echo 'Post for the day ' . get_the_date('j F, Y') . ' | '; bloginfo('name'); ?></title>
<?php elseif ( is_month() ): ?>
<title><?php echo 'Post for the month ' . get_the_date('F Y') . ' | '; bloginfo('name'); ?></title>
<?php elseif ( is_year() ): ?>
<title><?php echo 'Post for the year ' . get_the_date('Y') . ' | '; bloginfo('name'); ?></title>
<?php endif; ?>
But I am trying to make this same code in neat manner something like that:
<title>
<?php
if( is_home || is_front_page() ): bloginfo('name'); echo ' | '; bloginfo('description');
elseif( is_single() || is_page() ): wp_title('|', true, 'right'); bloginfo('name');
elseif( is_category() ): single_cat_title(); echo ' | '; bloginfo('name');
elseif( is_tag() ): single_tag_title(); echo ' | '; bloginfo('name');
elseif( is_day() ): echo 'Post for the day ' . get_the_date('j F, Y') . ' | '; bloginfo('name');
elseif( is_month() ): echo 'Post for the month ' . get_the_date('F Y') . ' | '; bloginfo('name');
elseif( is_year() ): echo 'Post for the year ' . get_the_date('Y') . ' | '; bloginfo('name');
endif;
?>
</title>
Kindly, tell where I am wrong.
Q2. When I tried to display bloginfo description it is not working. Notice that I am using static front-page for my theme. Those codes are as follow:
<?php if (is_single() || is_page()): if (have_posts()): while (have_posts()): the_post(); ?>
<meta name="description" content="<?php the_excerpt_rss(); ?>" />
<?php endwhile; endif; ?>
<?php elseif ( is_home() || is_front_page() ): ?>
<meta name="description" content="<?php bloginfo('description'); ?>" />
<?php endif; ?>
Kindly, Show me right way for Dynamic Title and Meta Description for my all post, pages, categories, tags and other pages.