我有一些在帖子中动态生成的短代码。
[简码 1][简码 2][简码 3] ...[简码 77]
我正在使用WP过滤器功能content_save_pre对内容运行preg_match并从短代码中删除所有数字。
所以:
[简码 1] 变为 [简码]
。
[简码 77] 变为 [简码]
这是我现在使用的
add_filter( 'content_save_pre' , 'preg_replace' , 10, 1);
funtion preg_replace ($content){
$content = preg_replace('/shortcode .]/', 'shortcode]', $content);
return $content;
}
我的问题是,在某些场合,两位数的短代码不会更改。这种方式可以工作(有 2 个点),但肯定有更好的方法来定位数字,以便将它们全部删除,无论家里有哪个。
$content = preg_replace('/shortcode ..]/', 'shortcode]', $content);
使用这个:
$content = preg_replace('/shortcode d+]/', 'shortcode]', $content);