Trim WordPress Content and Add Read More Link

by Mar 23, 2016Tutorials, Wordpress Code Snippets0 comments

Thought I’d share this wordpress code snippet with you. If you are trying to trim or limit the content shown from a post you can use this to limit the number of words. This snippet limits the content to 35 words with a Read More link.

Copy / Paste Code

<?php echo wp_trim_words( get_the_content(), 35, '...' ); ?>
<a href="<?php the_permalink()?>"> (Read More)</a>

You can change 35 to whatever word count you want as well as change Read More to say anything else you prefer.

Other Examples are:

Limits to 50 words, and says “Continue…”

<?php echo wp_trim_words( get_the_content(), 50, '' ); ?>
<a href="<?php the_permalink()?>"> Continue...</a>

Limits to 200 words, and says “Learn more >”

<?php echo wp_trim_words( get_the_content(), 200, '...' ); ?>
<a href="<?php the_permalink()?>"> Learn more ></a>

Pin It on Pinterest

Share This