• I have added the following code to my functions.php

    function gen_meta_desc() {
    global $post;
    
    if (!is_single()) {
        return;
    }
    
    //print_r($post);
    $meta = strip_tags($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', 'gen_meta_desc');

    But how do I get the description to output in the header?

    I have tried adding <meta name='description' content='$meta' /> in the header but it doesn’t work.

    What do I do?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trying to auto generate Meta Description.’ is closed to new replies.