Quantcast
Channel: Extreme Web Designs » wordpress-snippets
Viewing all articles
Browse latest Browse all 10

WordPress: Limit excerpt length

$
0
0

Rocky Dev

Have you ever thought of showing limited information about an article on the homepage of your blog? This limited information is called “Excerpt”. It can also be called as a “Post summary” or “Description of a post”. Here is a little snippet that will let you, in WordPress, limit excerpt length.

How to Limit excerpt length in WordPress

Simply paste the following function into functions.php file of your WordPress theme:

<?php

function limit_excerpt_length($string, $word_limit)
{
$words = explode(' ', $string);

return implode( ' ', array_slice($words, 0, $word_limit) );

}

?>

Then simply paste the following line of code in your theme, where you want to limit the excerpt length (most commonly used in index.php file)

<?php
//Simply change the number 50 to a number of your choice to limit the excerpt length
//up to the specified number
echo limit_excerpt_length(get_the_excerpt(),  '50');
?>

Your turn!

Do you know of any other ways to limit the excerpt length in WordPress? If yes, please feel free to share with us by commenting below.

WordPress: Limit excerpt length


Viewing all articles
Browse latest Browse all 10

Trending Articles