- Adding this snippet into the functions.php file of your WordPress theme will automatically create a meta description from your WordPress post, striping out all shortcodes and tags. Also ensure that you have it in the header.php of your WordPress theme or this snippet will not function.
- function create_meta_desc() {
- global $post;
- if (!is_single()) { return; }
- $meta = strip_tags($post->post_content);
- $meta = strip_shortcodes($post->post_content);
- $meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
- $meta = substr($meta, 0, 125);
- echo "<meta name='description' content='$meta' />";
- }
- add_action('wp_head', 'create_meta_desc');
Wednesday, 26 February 2014
Automatically create meta description from the_content
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment