Skip to content

Instantly share code, notes, and snippets.

@deeman
Created November 16, 2017 23:39
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 deeman/3f77ab69d2ea096a9212d771b1b433ad to your computer and use it in GitHub Desktop.
Save deeman/3f77ab69d2ea096a9212d771b1b433ad to your computer and use it in GitHub Desktop.
(SEO) Create Meta Description From Content
This creates a custom SEO function for meta description.
The function automatically create (155 words) Meta Description From Content.
function create_meta_desc() {
global $post;
if (!is_single()) { return; }
$meta = strip_tags($post->post_content);
$meta = strip_shortcodes($meta);
$meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
$meta = substr($meta, 0, 155);
echo "<meta name='description' content='$meta' />";
}
add_action('wp_head', 'create_meta_desc');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment