WordPress.org

Ready to get started?Download WordPress

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

$content = get_the_content();
$trimmed_content = wp_trim_words( $content, 40, '<a href="'. get_permalink() .'"> ...Read More</a>' );
echo $trimmed_content;

?>

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.