1

I changed theme/plugin now the post content still display shortcodes.

There are some tips around on hiding them, but everytime I use some content functions, the shortcodes shows up again. Also, my shortcodes are the "extended type" such [theshortcode id="34877"], [theshort size="large" "tiny"] etc so the tips on removing them from database doesn't work at all.

1 Answer 1

1

Please backup your database before trying

In your current theme, open the functions.php file and add the code below. In theshortcodeyouhate inform the shortcode you want to get rid of, note that even extended types works nicely!

Once you added this code, hit F5 and you are done.

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));
}
}

Thanks to wp-hackers mailing list

1
  • Hi Diana, it sounds like you solved the problem, so you should mark this as the accepted answer.
    – Ian Dunn
    Commented Jul 18, 2012 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.