Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Removing Visual Composer & Shortcodes From Wordpress Content

Original article explanation is here:

http://www.kirstencassidy.com/cleaning-up-formatting-shortcodes/

\[/vc(.*?)\]

\[vc(.*?)\]

\[custom_font(.*?)\]

\[/custom_font(.*?)\]

\[/vc_column_text(.*?)\]

\[vc_separator(.*?)\]
<hr>

\[/vc_column(.*?)\]

\[vc_row(.*?)\]

\[portfolio_list(.*?)\]

Finding shortcodes in general

(?!\[CDATA\[)\[(.*?)\]

Keeping some elements

(?!\[vc_single_image(.*?)\])(\[vc(.*?)\])

Steps

Step 1

// Remove Visual Composer Stuff Except Images
(?!\[vc_single_image(.*?)\])(\[vc(.*?)\])
\[/vc(.*?)\]

Step 2

// Remove Custom Fonts
\[custom_font(.*?)\]
\[/custom_font(.*?)\]

Step 3

# Change Visual Composer Images To...Actual Images

# Regex ID ONLY - Don't use - just to find IDs
$ (?<=\[vc_single_image image=")([0-9]*)(?=")

# WHOLE SHORTCODE
$ (\[vc_single_image image=")([0-9]*)(?=")(.*\])

# alternative
$ (\[vc_single_image(.*)image=")([0-9]*)(?=")(.*\])

# Replace with 
$ <PanelImage>$2</PanelImage>

Step 4

# Add more XML Elements 

# Find end of Content (use whatever element you like)
$ </Element>

$ </Element>\n\t\t<NewElement>\n\t\t</Panels>

** Other Helpers **

# Replace vc_video link with plain video
$ (\[vc_video link=['|"])([a-zA-Z://.?=_0-9]*)(['|"])(\])

with

$ $2

Why Remove Them In The First Place

http://www.themelab.com/put-shortcodes-in-a-plugin/

When a user changes themes, it can be a pain to go through the site's content and fix any of the shortcodes. Maybe a shortcode was not required in the first place, and this can be changed with regular html - eg a button can simply be changed from:

[button]Foo[/button]

to

<button>Foo</button>

Any styling associated with the theme will correctly be applied to the html.

Maybe it's better to keep the shortcode

For example, if a shortcode is already used site wide, it will be easier to keep the shortcode and retain the functionality.

Therefore extract the shortcode, and place it inside a plugin that can be used regardless of changes in themes at a later date.

An example would be:

[latest_post type="foo" number_of_columns="foo"]

If this is used in multiple places, simply create a plugin. Obviously, it would be better for the plugin to style it, however it's permissible for the theme to style it correctly.

Resources

Regex Helper

https://gist.github.com/gemmadlou/7a0189bfae6c2c7268de12f1de822b8a

@mohamdio

This comment has been minimized.

Copy link

commented Feb 12, 2018

Thanks for sharing this tutorial, I developed a free plugin named ( Shortcode Cleaner Lite ), to solve this exact problem.
https://wordpress.org/plugins/shortcode-cleaner-lite
Video demo: https://www.youtube.com/watch?v=dXVZ5bSUduc

It will Clean your WordPress content from any unused broken shortcodes, which it clean up unused, broken shortcodes from WordPress content automatically, so you can switch between themes and plugins without worrying and keep your content cleanly and fresh all the time, it is dealing with any theme (Divi, Avada..etc) shortcodes that are left when changing themes or plugins or page builders (Visual Composer, Elementor, Beaver…etc).

I hope it will be useful.

@Internapse

This comment has been minimized.

Copy link

commented Aug 30, 2018

Thanks @mohamdio!

Your plugin worked perfectly to clean out Visual Composer / WPBakery Page Builder code in literally a single click.

Amazing work! Saved me hours!

@kkri

This comment has been minimized.

Copy link

commented Sep 6, 2018

Just found the wonderful Shortcode cleaner lite plugin! After having cleaned the shortcodes, how to clean the databbase from Visual Composer tables? Thank you

@mohamdio

This comment has been minimized.

Copy link

commented Oct 10, 2018

@Internapse Thank you!

@kkri To clean up old/broken shortcodes within backend/database you should get the PRO version here:
https://codecanyon.net/item/shortcode-cleaner-clean-wordpress-content-from-broken-shortcodes/21253243
which the lite version just remove old/broken shortcodes within the frontend site.

@smarteseiten

This comment has been minimized.

Copy link

commented Feb 21, 2019

@mohamdio Can your tool REPLACE the shortcode by actual HTML-Code, or just delete or code-snippets?

Say like

[vc_row][vc_column][vc_single_image image=“12345″ img_size=“full“][/vc_column][/vc_row]

become

<img src="imagesource" alt="imagealt" />

edit: missing [code]-Tags added

@k1sul1

This comment has been minimized.

Copy link

commented Jun 11, 2019

I just wanted them all gone, so I ran this in the MySQL shell.

UPDATE wp_posts SET post_content = REGEXP_REPLACE(post_content, "\\[\/?vc(.*?)\]", "");

Note the double backslash. If you forget it, you'll replace all v's and c's with nothing, and the shortcodes will still be there.
This works for other shortcode as well, just replace vc.

Take a backup beforehand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.