Joe Huang
Joe Huang

Reputation: 6570

How to deactivate past shortcodes in Wordpress

Recently I changed the theme of my site, and I found many of my articles use a shortcode like this

[box]
    ....
[/box]

My new theme does not support it and I actually don't need this shortcode to function. I thought I could just write a empty function for the shortcode in function.php, like this

function shortcode_box() {
    return "";
}
add_shortcode('box', 'shortcode_box');

but it's not working.

Do you know any method to deactivate this short code?

Upvotes: 0

Views: 63

Answers (2)

Matt Gibson
Matt Gibson

Reputation: 38238

So, you want to leave the [box] bits in the posts and/or pages, but have them not do anything? Try a shortcode that passes through the content unchanged:

function shortcode_box( $atts, $content = null ) {
    return $content;
}
add_shortcode( 'box', 'shortcode_box' );

(For enclosing shortcodes, the return value of the function is used to replace the entire shortcode.)

Upvotes: 2

Tamil Selvan C
Tamil Selvan C

Reputation: 20229

Use remove_shortcode()

remove_shortcode('box');

Reference: http://codex.wordpress.org/Function_Reference/remove_shortcode

Upvotes: 1

Related Questions