Remove p tag from the_excerpt
In our recent project we want to use the excerpt as the meta description for single post. Here is the original codes:
[php]
/*
* output meta description info
*/
function ultra_meta_desc() {
echo ‘<meta name="description" content="’;
if (is_single()){
the_excerpt();
} else {
echo bloginfo( ‘description’ );
}
echo ‘"/>’;
}
[/php]
But the result is not what we had expected because it adds opening and closing p tags to the string. Can we use
get_the_excerpt
instead? The answer is no. Because get_the_excerpt must be used in the post loop that don’t apply to this case.
Here is the solution don’t be surprised after you find how simple it is – Just replace
the_excerpt
in line 7 with
the_excerpt_rss
. Here is we get:
[php]
/*
* output meta description info
*/
function ultra_meta_desc() {
echo ‘<meta name="description" content="’;
if (is_single()){
the_excerpt_rss();
} else {
echo bloginfo( ‘description’ );
}
echo ‘"/>’;
}
[/php]
Related reading: