通过这个小代码段,您可以删除all shortcodes 来自db:
在wordpress根目录中创建一个新文件,将下面的代码添加到文件中,调用创建的文件一次IMPORTANT:
这将直接从数据库中删除所有短代码-因此,请在执行文件之前进行备份!
<?php
require_once(\'wp-load.php\');
global $wpdb;
$allPosts = $wpdb->get_results("SELECT * FROM `wp_posts`");
foreach($allPosts as $post){
$content = RemoveShortcodes(\'[\', \']\', $post->post_content);
$wpdb->update(
\'wp_posts\',array(\'post_content\' => $content),array( \'ID\' => $post->ID )
);
}
function RemoveShortcodes($beginning, $end, $string) {
$beginningPos = strpos($string, $beginning);
$endPos = strpos($string, $end);
if ($beginningPos === false || $endPos === false) {return $string;}
$textToDelete = substr($string, $beginningPos, ($endPos + strlen($end)) - $beginningPos);
return RemoveShortcodes($beginning, $end, str_replace($textToDelete, \'\', $string));
}
?>