I want limit words in shortcode. I'm trying to made a WP plugin here i need limited words from get_the_excerpt{(); functions.
PHP has so many ways : Place this in functions.php:
function excerpt($num) {
$limit = $num+1;
$excerpt = explode(' ', get_the_excerpt(), $limit);
array_pop($excerpt);
$excerpt = implode(" ",$excerpt)."... (<a href='" .get_permalink($post->ID) ." '>Read more</a>)";
echo $excerpt;
}
Then, in your theme, use the code <?php excerpt('22'); ?>
to limit the excerpt to 22 characters.
Other way : <?php echo substr(get_the_excerpt(), 0,30); ?>
enjoy!!