Wednesday, June 6, 2012

How to automatically create meta description from content

Paste the following code into your functions.php file:


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 "";
}
add_action('wp_head', 'create_meta_desc');
 
?> 

No comments:

Post a Comment