THE PENDING DRAFT

Show “Read More” Link only when there is more content

January 4, 2015

Normally when you post something to your blog, it shows an excerpt on the homepage together with a “Read More” Link in some form which links to the actual content.

But what if your excerpt already is the whole content you want to display and there is no more content to read. Of course you could use the_content inside your loop. That works in most situations, but in some situations you actually wan’t to check whether there is more inside the post than what you already got with your excerpt.

After a bit of fiddling around with different snippets, i came up with this solution, which still has some flaws, but works for what i used it now.

<?php if ( strlen(get_the_content()) > strlen(get_the_excerpt()) ) : ?>
  <p><a href="<?php the_permalink(); ?>" class="more-link">More</a></p>
<?php endif ?>

What it does is comparing the length of the strings of get_the_content() and get_the_excerpt() and only output our custom more link, if the content is longer.

I’m not 100% sure if this is the proper way of doing this, but it worked for me. If you know any other ways of achieving the same result, go ahead and add it in the comments.

WordPress.org Support Thread 

Leave your comment