Using the Excerpt as a Description

Listing 7-17 shows how to use the excerpt as the meta description tag for single posts and pages. Since the_excerpt() prints directly to the screen and can't be passed to other PHP functions, you can't wrap it in the esc_attr() function, as you normally would when using a template tag as an HTML attribute. Instead, you use the_excerpt_rss(). This function formats the excerpt for RSS feeds, but in this case it will work equally well in your description attribute, since excerpts can't contain HTML.

Listing 7-17. Using the_excerpt as a meta description

<meta name="description" content="<?php the_excerpt_rss(); ?>" /> <?php endif; ?>

Was this article helpful?

0 0

Post a comment