Viewing 11 replies - 1 through 11 (of 11 total)
  • I’d consider using what is posted in the thread you referenced with a conditional
    <?php if (is_single()) { ?>
    code to run
    <?php } ?>

    https://codex.www.ads-software.com/Conditional_Tags

    Thread Starter sallam

    (@sallam)

    thanks. Forgive my being newbie in php, so will it be like that?:

    <?php if (is_single()) { ?>
    <meta name=”description” content=”<?php echo htmlentities(get_the_excerpt()); ?>” />
    <?php } ?>

    and where do I put that code, which file?

    The meta tags go in the header – you will see other meta tags there, too. However, if that is the code from the other thread, I doubt it will work. the_excerpt() is generated in the loop, but don’t take my word for it, give it a whirl. If you get an empty description then my hunch is correct. I say “hunch” because though I am positive, someone in the other thread says it works but I’d still bet it doesn’t.

    Thread Starter sallam

    (@sallam)

    yes, you’re right
    All I got now is empty descriptions!

    <meta name=”description” content=” ” />

    why its not getting WordPress pre-generated excerpts?
    can you advise somehow a change in the code to make it work?

    Nope I can’t because the post is not pulled until the loop is run so until then there is no description to be had. I suspect some php guru can hook you up but it ain’t gonna be me – can’t get past the “hack” stage to think like a programmer ??

    Thread Starter sallam

    (@sallam)

    wait, even after I used it without the if part, it still brought empty description!

    <meta name=”description” content=”<?php echo htmlentities(get_the_excerpt()); ?>” />

    is that excerpt something I must type myself when posting or what?
    because I dont..

    I believe you’re still getting an empty description because of what Beel said. You’re trying to call the meta tag info before the loop is used, so there’s no information to insert into the tag. Atleast that’s what I’m thinking is happening.

    There are a couple plugins that handle this:

    https://codex.www.ads-software.com/Plugins/Meta

    Someone has done the work (thanks Kafkaesqui)
    https://www.ads-software.com/support/topic.php?id=21710#post-163541

    From looking at the code, the only drawback is that it will not “fake” the excerpt but it will display if one actually exists (which I suspect would work better as a description anyway)

    I was iffy about the code when I wrote it, since I’ve reached the opinion there are better ways to do these sorts of things than hijacking the excerpt. But if you don’t use it for actual excerpts, and make sure it’s not output for rss (such as turning on full feed), then…why not.

    This worked perfectly for me. Download the following plugin:

    https://guff.szub.net/downloads/head-meta-desc.zip

    Extract the head-meta-desc.php, upload it to your wp-content/plugins directory and then activate ‘Head Meta Description’ under Plugins in the Dashboard.

    Insert the following code into your <head></head> section (generally found in the header.php file):

    <?php head_meta_desc(); ?>

    This will generate the following code:

    <meta name=”description” content=”(whatever the first X number or words you have for that page’s post)” />

    There are a couple variables in the plugin: $desc_length sets the number of words of the post or Page to place in the meta tag. Very useful if you want to add more or less info for the description’s content. I personally have mine set to 50 words.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘how to auto generate description meta tags?’ is closed to new replies.