WordPress Function : wp trim words()
Syntax[edit | edit source]
<?php $trimmed_text = wp_trim_words( $text, $num_words = 55, $more = null ); ?>
Parameters[edit | edit source]
||(String) (Required) Text that will be shortened or trimmed.|
||(Integer) (Required) Number of words to which text will be restricted.|
||(String) (Optional) What to append if $text needs to be trimmed.|
Trimming post content[edit | edit source]
This function shortens the text to a specified number of words and returns the shortened text.
<?php echo wp_trim_words( get_the_content(), 40, '...' ); ?>
In the above example we are passing the post content to the function. It will restrict the length of the content to 40 words and will trim rest of the words.
This article is an extract of the original Stack Overflow Documentation created by contributors and released under CC BY-SA 3.0. This website is not affiliated with Stack Overflow