函数
wpautop( string $pee, bool $br = true )
描述
用段落元素替换双换行符。
一组正则表达式替换,用于识别用换行符格式化的文本,并用 HTML 段落标签替换双换行符。转换后剩余的换行符变成 <> 标签,除非 $br 设置为 '0' 或 'false'。
参数
$pee,( string ) (必需) 要格式化的文本。
$br,( bool ) (可选)默认值:真。如果设置,这将在分段后转换所有剩余的换行符。<script>、<style>和标记内的换行符<svg>不受影响。
返回值
(字符串)已转换为正确段落标签的文本。
猫斯基·划重点
可以从主题中禁用 wpautop 过滤器 functions.php:
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
相关函数
来源
文件:wp-includes/formatting.php
更新日志
| 版本 | 描述 |
|---|---|
| 0.71 | 介绍. |
示例
原始文本:
Some long text
that has many lines
and paragraphs in it.
经过 wpautop 转换:
$some_long_text = // Start Text
Some long text
that has many lines
and paragraphs in it.
// end text
echo wpautop( $some_long_text );
显示文本:
<p>Some long text<br/>
that has many lines</p>
<p>and paragraphs in it.</p>
本文首发于 猫斯基 。