目录
描述
译文
将文本中的成对换行符换成HTML段落符号(
...
)
WordPress使用该函数来过滤文章内容和摘要。
原文
将文本中的两个换 符转换 HTML 落(<p>...</p>
),其余的换行转换成 <br />
WordPress 使用这个函数对日志内 (the_content()
)和摘要(the_excerpt()
)进行格 化处理。
wpautop() 描述
用法
<?php wpautop( $foo, $br ); ?>
wpautop() 用法
参数
$foo
(string) (必填) 将格式化的文本。
默 值: None
$br
(boolean) (可选) 保留 符,当设置为 true ,段落 换完成之后余下 换行 转换 <br /> HTML 标签,script 和 style 后面的换行符不受影响。
默认值: true
wpautop() 参数
返回值
示例
Basic usage
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ <?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:
1 2 3 4 5 6 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ <p>Some long text<br/> that has many lines</p> <p>and paragraphs in it.</p> |
wpautop() 示例
注意
禁止过滤器
可以在 functions.php
中使用下面的代码取消 WordPress 使用 个函数过滤日志内容和摘要:
1 2 3 4 5 6 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' ); |
There's also a plugin available to enable/disable the 过滤器 on a post-by-post basis.
wpautop() 注意
源文件
wpautop() 函数的代码位于 wp-includes/formatting.php
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ /** * Replaces double line-breaks with paragraph elements. * * A group of regex replaces used to identify text formatted with newlines and * replace double line-breaks with HTML paragraph tags. The remaining line-breaks * after conversion become <br>> tags, unless $br is set to '0' or 'false'. * * @since 0.71 * * @param string $pee The text which has to be formatted. * @param bool $br Optional. If set, this will convert all remaining line-breaks * after paragraphing. Default true. * @return string Text which has been converted into correct paragraph tags. */ function wpautop( $pee, $br = true ) { $pre_tags = array(); if ( trim($pee) === '' ) return ''; // Just to make things a little easier, pad the end. $pee = $pee . " "; /* * Pre tags shouldn't be touched by autop. * Replace pre tags with placeholders and bring them back after autop. */ if ( strpos($pee, '<pre') !="=" false="" )="" {="" $pee_parts="explode("></pre')> |
wpautop() 源文件
- 原文:http://codex.wordpress.org/Function_Reference/wpautop
- 翻译:黄聪@WordPress之魂