0

I changed a wordpress theme on an old site and removed all plugins which were unnecessary.

All went well except for a shortcode that was used by the earlier author shows up on every post.

For example,

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu faucibus ipsum, id sagittis diam. Nam cursus ipsum quis dictum iaculis.

[spacer height=”10px”]

Quisque pellentesque risus risus, convallis consectetur odio malesuada non. Vivamus quis consequat diam. Nullam ac molestie purus. Vivamus id diam molestie, pulvinar urna eu, luctus purus. Sed ut cursus diam, sit amet tincidunt arcu. Integer blandit aliquam porttitor.

[spacer height=”5px”]

In consectetur dolor nulla, quis efficitur lectus tristique eu.

Is there a way I can remove this using the database on phpmyadmin. When I search the term it shows up in many places but I don't know more than this.

1

I love to use this tool, Search and Replace for WordPress Databases. It is basically a PHP script that is written for WordPress usage (but of course can be used with any database). When placed in the WordPress project, it automatically detects and loads the Database using data from wp-config.php file.

It enables you to make database queries based on regex, with a 'dry runs' - you will see a preview of the data that will be changed, but no real changes would be made. Also, it is serialization aware, meaning, if the variable you are replacing is inside a serialized object, it will safely be replaced, without breaking the serialization.

Setup is easy, just drop the folder in the WP root, and navigate the browser to the main PHP file. Remember to remove it afterwards.

I think you will love it as well, but remember to backup and double check before any live runs.

3

Site can be broken when you will update the content via SQL. I am giving a simple code and it will hide the [spacer height=”5px”] at front end.

Open the functions.php file of your current theme and add this code at end of the file.

add_shortcode( 'spacer','wse2019_remove_spacer' );
function wse2019_remove_spacer( $atts ) {
    return '';
}

It will automatically delete(basically it is hiding) the shortcode from your all existing posts/pages.

0

If you know which particular shortcode you want to remove and you want to remove it permanently from your database, you can simply do a SQL query with the command below:

UPDATE wp_post SET post_content = REPLACE(post_content, '[shortcodename]', '' );

Replace “shortcodename” with the shortcode you want to remove.

Note: This is not a foolproof method because different shortcodes can come with different attributes and value, making it hard to form a catch-all SQL query.

0

The simplest workaround I can think of is to define the shortcode and output an empty string. Add this code to functions.php of the current theme or in a custom plugin:

function wpse329827_ignore_spacer( $atts ) {
    return "";
}
add_shortcode( 'spacer', 'wpse329827_ignore_spacer' );

If you want to completely remove the shortcode, there are some plugins out there that can make search and replace queries for you like this and this.

If you have shell access to your server you can do the search-replace manually using wp search-replace command with --regex option.

Note that you should make a database backup before you do any replace operation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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