• benw2811

    (@benw2811)


    Is there anyway that I can automate the generation of META description tags? For example it automatically, unless I tell it differently, uses the first 160 characters of each post?

    Thanks in advance for your help.

Viewing 1 replies (of 1 total)
  • Michael

    (@alchymyth)

    you could try and add some code like this to header.php:

    <meta name="description" content="<?php
    if (have_posts()) : while (have_posts()) : the_post();
    $excerp = get_the_excerpt();
    $excerp = strip_tags($excerp);
    $excerp = preg_replace('/... &raquo; read more &raquo;/', ' - ', $excerp);
    if(!is_singular()) { $excerp = substr($excerp, 0, 160) ; }
    echo get_the_title().' : '.$excerp .' - ';
    endwhile; endif; wp_reset_query();
    ?>
    " />

    this would echo:
    – the full excerpt in single post and page,
    – a 160 character shortend excerpt on index and other pages,
    in the meta description tag.

Viewing 1 replies (of 1 total)
  • The topic ‘Automating META Description Tags’ is closed to new replies.