WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp trim words

Description

This function trims text to a certain number of words and returns the trimmed text.

Usage

<?php $trimmed wp_trim_words$text$num_words 55$more null ); ?>

Parameters

$text
(string) (required) Text to trim
Default: None
$num_words
(integer) (optional) Number of words
Default: 55
$more
(string) (optional) What to append if $text needs to be trimmed.
Default: '&hellip;'

Return Value

(string) 
Trimmed text.

Examples

An example which strips formatting:

<?php
echo wp_trim_words( get_the_content(), 40, '...' );
?>

Change Log

  • Since: 3.3.0

Source File

wp_trim_words() is located in wp-includes/formatting.php.

Related

How to use wp_trim_words in WordPress

See also index of Function Reference and index of Template Tags.