Aller au contenu
FR

Limit your Excerpts in a WordPress theme

Version audio de cet article

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); ?>