Skip to content

Instantly share code, notes, and snippets.

@ms-studio
Last active April 7, 2022 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ms-studio/1628192 to your computer and use it in GitHub Desktop.
Save ms-studio/1628192 to your computer and use it in GitHub Desktop.
WordPress meta description tag
<?php // ** DESCRIPTION v.0.2 **
if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post();
?><meta name="description" content="<?php
$descr = get_the_excerpt();
$text = str_replace( "\r\n", ', ', trim($descr) );
echo esc_attr($text);
?>" />
<?php endwhile; endif; elseif(is_home()) :
?><meta name="description" content="<?php bloginfo('description'); ?>" />
<?php endif; ?>
@ms-studio
Copy link
Author

Problem with v.0.1: this won't filter out "a href" tags. We need to sanitize the content and remove links.

@ms-studio
Copy link
Author

another method:

http://www.texto.de/the_excerpt-ohne-anfuehrungszeichen-und-shortcodes-1770/

echo htmlentities(strip_tags(get_the_excerpt()));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment