开发者

Preg Replace Wordpress tags

I'm displaying wordpres开发者_运维知识库s content on my own site.

However the content has such things as:

[caption id="attachment_367" align="aligncenter" width="432" caption="Version 2010!!"]

I would basically like to strip anything thats inside [] and the [] themselves.

Help greatly appreciated!


The regular expression you want is /\[.*?\]/

<?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!"
?>


So code like [caption id="attachment_367" align="aligncenter" width="432" caption="Version 2010!!"] looks like a shortcode to me.

If you want it to do nothing, you could add this to the functions.php file in your theme (if your theme does not have that file, you would need to create it and enclose this code inside <?php and ?>:

function do_nothing_caption() {
  return '';
}
add_shortcode('caption', 'do_nothing_caption');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜