Support » Themes and Templates » get_the_excerpt – Outside the Loop

  • I’m trying to figure out why get_the_excerpt is delivering nothing except a line break in WP2.6. I’m echoing tags and the excerpt for meta keywords and description in my header file. I do this by setting $post as global in the header, if it’s a single post, then echoing tags through a foreach, then the excerpt via get_the_excerpt.

    This works without problem in another blog I have, which is WP2.5.1. On the WP2.6 blog I’m having trouble with, echoing the tags works fine but get_the_excerpt results in only a line break. Edit: In both cases, I am not specifying an excerpt, but relying on the default 55-word filter inherent to WP.

    Was get_the_excerpt changed between 2.5.1 and 2.6? Am I missing something brilliantly simple?

    Here’s my code, outside the loop, in header.php:

    To echo the excerpt:

    <?php global $post;
       if (is_single()) {
          echo strip_tags(get_the_excerpt($post->ID));
       } ?>

    To echo the tags ($post is already global):

       if (is_single()) {
          foreach(get_the_tags($post->ID) as $tag) { echo $tag->name . ', '; }
       } ?>

    I hope this makes sense, and I appreciate any help! Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Just a side note… even upgrading to 2.6.5, I get the same result outside the loop by making $post global. In ver.2.5.1 I am able to echo get_the_tags, get_the_excerpt, and even get_the_category. In version 2.6+, get_the_tags works just fine, but get_the_excerpt, and even get_the_category isn’t working.

    I’m stumped.





    maybe include something like


    after you is_single() line to make sure that the $post object is actually loaded with data. If you get a NULL result then obviously it isn’t. And if it is loaded then you’ll see an ID element.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_the_excerpt – Outside the Loop’ is closed to new replies.