I’m glad you asked! Finally, we’ll get to those Conditional WordPress Tags I talked about earlier. Here is the code below:
<meta name=”description” content=”<?php if (have_posts() && is_single() OR is_page()):while(have_posts()):the_post();
$out_excerpt = str_replace(array(“\r\n”, “\r”, “\n”), “”, get_the_excerpt());
echo apply_filters(‘the_excerpt_rss’, $out_excerpt);
endwhile;
elseif(is_category() OR is_tag()):
if(is_category()):
echo “Posts related to Category:
“.ucfirst(single_cat_title(“”, FALSE));
elseif(is_tag()):
echo “Posts related to Tag:
“.ucfirst(single_tag_title(“”, FALSE));
endif;
else: ?><?php bloginfo(‘description’) ?>
<?php endif; ?>” />
Install this code in between your WordPress site’s <head></head> section in the ‘header.php’ file. Basically, this code will do a couple things.
If the search engine/user views your site’s individual pages or categories, the conditional WordPress tags kick in and tell the browser/webcrawler to grab the opening excerpt of your post/page and use that as the META Description tag.
If the search engine/user lands on the homepage, it will tell the browser/webcrawler to display the default Blog Description (which you specify on the ‘Settings’ page) as your META Description.
<meta name=”description” content=”<?php if (have_posts() && is_single() OR is_page()):while(have_posts()):the_post();
$out_excerpt = str_replace(array(“\r\n”, “\r”, “\n”), “”, get_the_excerpt());
echo apply_filters(‘the_excerpt_rss’, $out_excerpt);
endwhile;
elseif(is_category() OR is_tag()):
if(is_category()):
echo “Posts related to Category:
“.ucfirst(single_cat_title(“”, FALSE));
elseif(is_tag()):
echo “Posts related to Tag:
“.ucfirst(single_tag_title(“”, FALSE));
endif;
else: ?><?php bloginfo(‘description’) ?>
<?php endif; ?>” />
Install this code in between your WordPress site’s <head></head> section in the ‘header.php’ file. Basically, this code will do a couple things.
If the search engine/user views your site’s individual pages or categories, the conditional WordPress tags kick in and tell the browser/webcrawler to grab the opening excerpt of your post/page and use that as the META Description tag.
If the search engine/user lands on the homepage, it will tell the browser/webcrawler to display the default Blog Description (which you specify on the ‘Settings’ page) as your META Description.
No comments:
Post a Comment