The Beginning of the Journey
Recently I took over a massive WordPress website with a large number of posts. The previous owner had used Visual Composer to create all the content. While Visual Composer is a powerful tool (enter sarcasm here) , it leaves a trail of shortcodes like [vc_row], [vc_column], and others all over the place. My task was to remove these shortcodes from both the front end and backend of the site to make it easier to manage and faster to load so I can deal with the content only.
The Challenge
At first, I thought it would be a straightforward task. I quickly found a few free plugins that claimed to remove shortcodes. However, I soon realized that these plugins only cleaned up the shortcodes on the front end, meaning visitors wouldn’t see them, but the backend (where the client does all the editing) was still cluttered with these [vc_] shortcodes. This was not going to work for me—I needed a solution that addressed both ends.
Finding the Solution
A more effective method is to use a custom PHP script.
This script allowed me to target and remove all [vc_] shortcodes directly from the database, ensuring they were gone from both the front end and backend. Here’s how I did it:
Step 1: Backup Your Database
Before making any changes, it’s crucial to create a complete backup of your WordPress database. This ensures you can restore your site if anything goes wrong.
- Install and Activate a Backup Plugin: Use a backup plugin like UpdraftPlus to create a backup.
- Create a Backup: Follow the plugin instructions to create a full database backup.
Step 2: Write the PHP Script
I wrote a PHP script to remove all shortcodes starting with [vc_ from the post content. Here’s the script I used:
<?php require('wp-load.php'); global $wpdb; // Get all posts containing the shortcode $posts = $wpdb->get_results("SELECT ID, post_content FROM wp_posts WHERE post_content LIKE '%[vc_%'"); foreach ($posts as $post) { $content = $post->post_content; // Use regex to remove all shortcodes starting with [vc_ $updated_content = preg_replace('/\[vc_[^\]]*\]/', '', $content); // Check if the content was updated if ($updated_content !== $content) { $wpdb->update( 'wp_posts', array('post_content' => $updated_content), array('ID' => $post->ID) ); } } echo "Shortcodes removed successfully."; ?>
Step 3: Upload and Execute the PHP Script
- Save the Script: Save the script as
remove-vc-shortcodes.php. - Upload the Script: Upload the script to the root directory of your WordPress installation.
- Execute the Script:`
- Using WP-CLI:
wp eval-file remove-vc-shortcodes.php - Using a Web Browser:
- Access the script via your web browser:
http://yourdomain.com/remove-vc-shortcodes.php
- Using WP-CLI:
Step 4: Verify the Changes
After running the script, I checked several posts to ensure the shortcodes were removed and the content appeared as expected. I also cleared the cache to see the changes on the front end.
Summary
By following these steps, I was able to effectively remove [vc_] shortcodes from both the front end and backend of my WordPress database. The website is now cleaner, easier to manage, and faster.
Need Help?
If you’re facing a similar challenge, don’t hesitate to try this method. It worked wonders for my site, and it can do the same for yours. If you have any questions or run into issues, feel free to leave a comment below or reach out to me.


