我们在WordPress后台发表文章的时候,如果你什么样式都没有写,编辑器会自动将你的代码格式化,例如:你写一行字,它会自动给你的文字加上
通过使用短代码,可以对WordPress编辑器自动格式化进行过滤。在使用主题的 functions.php 里加入下面的代码:function my_formatter($content) {
$new_content = '';
$pattern_full = '{(\[raw\].*?\[/raw\])}is';
$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($pieces as $piece) {
if (preg_match($pattern_contents, $piece, $matches)) {
$new_content .= $matches[1];
} else {
$new_content .= wptexturize(wpautop($piece));
}
}
return $new_content;
}
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'my_formatter', 99);
添加这段代码后,我们写发表文章的时候使用 [raw] 显示代码 [/raw] 这样的短代码形式写代码即可(在编辑器的HTML方式下),这样raw 区域里的代码是不会被自动添加上其他标签的。
Wordpress下载:
软件大小:6.28MB
软件类别:国外软件 | 博客系统
软件语言:简体中文
运行环境:PHP/Mysql
软件授权:免费版
更新时间:2013-7-24 16:05:30
软件大小:7.37MB
软件类别:国外软件 | 博客系统
软件语言:英文
运行环境:PHP/MySQL
软件授权:开源软件
更新时间:2016-2-3 9:47:33