WordPress 函数:wpautop

将文本中的两个换行符转换成 HTML 段落 (<p>...</p>),其余的换行转换成 <br />

WordPress 使用这个函数对日志内容和摘要进行格式化处理。

用法

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

参数

$foo
(string) (required) 将格式化的文本。
Default: 无

$br
(boolean or integer) (optional) 保留换行符,当设置为 true ,段落转换完成之后余下的换行符将转换成 <br />
HTML 标签,script 和 style 后面的换行符不受影响。
Default: 1

返回值

(string)
已经转换成正确段落标签的文本。

实例

<?php
$some_long_text = <<<TXT
Some long text
that has many lines

and paragraphs in it.
TXT;

echo wpautop($some_long_text);
?>

输出结果:

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

注解

可以使用下面的代码取消 WordPress 使用这个函数过滤日志内容和摘要:

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

修改记录

Since: 0.71

源文件

wp-includes/formatting.php