Please backup your database before trying
在当前主题中,打开
functions.php
文件并添加下面的代码。在里面
theshortcodeyouhate
通知您要删除的短代码,请注意,即使是扩展类型也可以很好地工作!
添加此代码后,按F5即可完成。
add_action (\'init\',\'remove_shortcode_from_db\'); //you can choose any other actions such wp_head etc
function remove_shortcode_from_db($shortcode = \'theshortcodeyouhate\') {
global $wpdb;
$posts = $wpdb->get_results("SELECT ID,post_title,post_content FROM
$wpdb->posts");
$regex =
\'/\\[(\\[?)(\'.$shortcode.\')\\b([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([
^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)/s\';
foreach($posts as $post) {
$final = preg_replace($regex,\'\',$post->post_content);
$change = $wpdb->update( $wpdb->posts, array(\'post_content\' =>
$final), array(\'ID\' => $post->ID));
}
}
感谢wp黑客邮件列表