Just show the excerpt for Meta Description
Monday, November 16th, 2009Here’s a quick script if you want to just display the excerpt for the meta description. I’m using the All In One SEO plugin, which can automatically generate the meta description, but it will use the entire content as opposed to the excerpt. If you’re using a plugin like Smart Youtube this can be a problem. It’s tempting to just add a meta description tag using the_excerpt within the loop on a single page, but that wouldn’t validate, so add this to your header instead. Enjoy!
<?php if (is_single()):while(have_posts()):the_post();
echo ‘<meta name=”description” content=”‘;
$out_excerpt = str_replace(array(”\r\n”, “\r”, “\n”), “”, get_the_excerpt());
echo apply_filters(’the_excerpt_rss’, $out_excerpt);
echo ‘” />’;
endwhile;
endif;
?>
Thanks to Michele for the snippet
Tags: description, excerpt, header, meta
Posted in SEO | 3 Comments »
Meta Title Tags for Wordpress
Tuesday, November 10th, 2009All-In-One SEO is a great plugin for Wordpress and handles all your SEO needs. However, Facebook requires an additional meta tag which All-In-One doesn’t handle, the meta title tag. However, there is an easy way to add this tag in Wordpress, using the built in function wp_title.
The code looks like this, just add it into your header.php file:
<meta name=”title” content=”<?php wp_title(”,true,”); ?>”>
The only problem is that the homepage will be blank, fix it like this:
<?php
if (is_front_page()) {
echo ‘<meta name=”title” content=”BLOG TITLE” />’;
} else {
echo ‘<meta name=”title” content=”‘;
wp_title(”,true,”);
echo ‘” />’;
}
?>
Here is a link to the full reference for wp_title. Keep in mind this displays the same thing as using the_title within the loop, it doesn’t display the full page title, so if you’re changing the title with All In One SEO for example to include category, blog title, etc. this won’t be reflected here, which isn’t necessarily a bad thing.
Enjoy your titles!
Tags: Facebook, Meta Tag, Share, Social Media, Title
Posted in SEO | 3 Comments »
