Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
    
Hi Diana, it sounds like you solved the problem, so you should mark this as the accepted answer. –  Ian Dunn Jul 18 '12 at 6:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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