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/wpautop

Contents

Description

Changes double line-breaks in the text into HTML paragraphs (<p>...</p>).

WordPress uses it to filter the content and the excerpt.

Usage

 <?php wpautop$foo$br ); ?> 

Parameters

$foo
(string) (required) The text to be formatted.
Default: None
$br
(boolean) (optional) Preserve line breaks. When set to true, any line breaks remaining after paragraph conversion are converted to HTML <br />. Line breaks within script and style sections are not affected.
Default: true

Return Values

(string) 
Text which has been converted into correct paragraph tags.

Examples

Basic usage

<?php
$some_long_text = // Start Text
Some long text
that has many lines

and paragraphs in it.
// end text

echo wpautop( $some_long_text );
?>

This should echo the string with <p> tags around the paragraphs, like this:

<p>Some long text<br/>
that has many lines</p>
<p>and paragraphs in it.</p>

Notes

Disabling the filter

Some people choose to disable the wpautop filter from within their theme's functions.php:

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

There's also a plugin available to enable/disable the filter on a post-by-post basis.

Changelog

Since: 0.71

Source File

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

Resources

http://ma.tt/scripts/autop/

Related

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