Forums

Trying to auto generate Meta Description. (3 posts)

  1. Hampstead
    Member
    Posted 2 years ago #

    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?

  2. Hampstead
    Member
    Posted 2 years ago #

    Can anybody help me with this?

  3. revolutionbegins
    Member
    Posted 1 year ago #

    I would like to know this as well

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.