我在我自己的网站上显示wordpress内容。Preg替换Wordpress标签
然而内容具有这样的事情:
[caption id="attachment_367" align="aligncenter" width="432" caption="Version 2010!!"]
我将基本上要剥离的内部[]和[]本身任何这就是。
帮助非常感谢!
我在我自己的网站上显示wordpress内容。Preg替换Wordpress标签
然而内容具有这样的事情:
[caption id="attachment_367" align="aligncenter" width="432" caption="Version 2010!!"]
我将基本上要剥离的内部[]和[]本身任何这就是。
帮助非常感谢!
你想要的正则表达式是/\[.*?\]/
<?php
$old_content = 'Hello [caption id="attachment_367" align="aligncenter" width="432" caption="Version 2010!!"] World!';
$new_content = preg_replace('/\[.*?\]/', '', $old_content);
echo $new_content; // result: "Hello World!"
?>
所以像[caption id="attachment_367" align="aligncenter" width="432" caption="Version 2010!!"]
代码看起来像shortcode给我。
如果你想让它什么都不做,你可以添加这个到functions.php
文件在你的主题(如果你的主题没有这个文件,你需要创建它,并附在代码里<?php
和?>
:
function do_nothing_caption() {
return '';
}
add_shortcode('caption', 'do_nothing_caption');
他们都是'[caption]'还是有其他'[shortcode]'类型的内容标签? – artlung 2010-06-09 18:30:25