NB: Make sure you do a back up of your theme, files and database before attempting the tutorials

Easy

---- Last modified : Sep 08 2022

Estimated reading time : 0 minutes, 52 seconds - 75 words

This tutorial will show you how to create a function that will set a limit of characters for your excerpts in the WordPress theme you’re using.
We trigger a simple function that will display the post content by converting it in an excerpt using the $count variable:

function templify_limit($count){
  $permalink = get_permalink($post->ID);
  $excerpt = get_the_content();
  $excerpt = strip_tags($excerpt);
  $excerpt = substr($excerpt, 0, $count);
  $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
  $excerpt = $excerpt.' ...';
  return $excerpt;
}

Now we will display our WordPress function in our theme by specifying the number of characters with the $count variable:

<?php echo templify_limit(200); ?>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>