WordPress excerpt not working

I am using the latest WordPress version and when I use <?php the_excerpt(); ?> on the index page it doesn’t show the post excerpt.

I tried putting in the_content() instead and it worked, so I’m assuming there is something wrong.

Read More

My code:

<?php get_header(); ?>


<?php if (have_posts()) : ?>
<div id="post-area">
<?php while (have_posts()) : the_post(); ?> 

        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
         <?php if ( has_post_thumbnail() ) { ?>
         <div class="gridly-image"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail( 'summary-image' );  ?></a></div>
          <div class="gridly-category"><p><?php the_category(', ') ?></p></div>

          <?php } ?>
                <div class="gridly-copy"><h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                <p class="gridly-date"><?php the_time(get_option('date_format')); ?>  </p>


            <p class="gridly-excerpt"><?php the_excerpt(); ?></p>
            <div class="read-more">
                <a class="read-more-button" title="Read More" href="<?php the_permalink() ?>">Read More</a>
            </div>
         </div>
       </div>



<?php endwhile; ?>
</div>
<?php else : ?>
<?php endif; ?>

<?php next_posts_link('<p class="view-older">View Older Entries</p>') ?>


<?php get_footer(); ?>

I am using this theme: http://www.eleventhemes.com/gridly-theme/

Thanks

Related posts

Leave a Reply

2 comments

  1. I actually solved it myself, it turns out there was this piece of code which I removed that solved my problem:

        function custom_excerpt_length( $length ) {
            return 0;
        }
        add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
    

    Not sure what it does though, but it doesn’t seem like I need it.

  2. The function that gets the excerpt, and the_excerpt itself, can be located in wp-includes/post-template.php. It looks like this:

    function get_the_excerpt( $deprecated = '' ) {
            if ( !empty( $deprecated ) )
                    _deprecated_argument( __FUNCTION__, '2.3' );
    
            $post = get_post();
    
            if ( post_password_required() ) {
                    return __( 'There is no excerpt because this is a protected post.' );
            }
    
            return apply_filters( 'get_the_excerpt', $post->post_excerpt );
    }
    

    Corresponding to the_content there is a get_the_content which retrieves the post and the post content in the same way. So if one works and the other doesn’t, this indicates that there simply isn’t any except? Have you double checked that there really is an excerpt for the post? Did you check the post_except field in the database?

    If you do that, and it looks like there should be an excerpt to display, the only possible explanation is that you have a function hooked to either get_the_excerpt or the_excerpt that returns nothing. So you have to locate the code that does that. If you are familiar with such tools, you could search for any occurrence of said hooks in your plugins and theme. If you’re not, you may want to try to disable the plugins one by one and maybe trying a different theme.