|

|

How to remove Divi shortcodes the easy way


The Divi theme and the Divi Page Builder plugin are widely used on WordPress websites. Divi offers drag-and-drop functionality and a broad range of add-ons. Heck, we adopted Divi ourselves for several years when building client websites. And we still actively support it on multiple WordPress sites. But if you later need to switch to a different theme or page builder, there are some hurdles to get over.

The problem with migrating from Divi

While it offers lots of benefits, many developers warn clients against adopting Divi in the first place. They argue that Divi locks you into its ecosystem, which means if you ever decide to switch to a different theme or platform, you might face challenges in migrating your content seamlessly.

The biggest challenge in migrating from Divi is dealing with the shortcodes that it injects liberally throughout your page content. Once Divi is inactive, these shortcodes no longer function. Instead, they display to visitors on your web pages.

Here’s a real example from a live website that we found with a quick and simple Google search:

The good people at Save The High Street seem at some point to have migrated the theme on their WordPress site from Divi to Ultra by Themify.

Removing Divi shortcodes – the challenge

Because Divi shortcodes are typically splattered throughout your content, removing them manually page-by-page can be tedious, fiddly, and, for a big website, heavily time-consuming.

If you face this prospect but want to retain the will to live, you’re going to need a smarter way to handle the challenge.

Removing Divi shortcodes – the opportunistic solution

Simply add the snippet below (courtesy of Victor M. Font Jr. and available on GitHub here) at the bottom of the functions.php file for your new theme:

<?php

function remove_divi_shortcodes( $content ) {
    $content = preg_replace('/\[\/?et_pb.*?\]/', '', $content);
    return $content;
}

Now, whenever a visitor loads one of your web pages, the function will run and permanently clean out any Divi tags from that page.

This opportunistic approach to removing Divi shortcodes is fine if you are happy for the existing content to render essentially unformatted. However, it is often the case that your pages will need some work to display as you would like them with the new WordPress theme. In this situation, you will want to clean *all* pages of redundant Divi clutter before working on the new look.

Removing Divi shortcodes – the Big Bang solution

The Big Bang approach to cleaning up Divi code is to remove ALL such code from all pages and posts programmatically in one blast. That will then allow you to work systematically through the cleaned-up pages to add appropriate formatting and functionality under your new theme.

Technically, this is a question of running some SQL queries on the WordPress database. However, it is safer and generally easier to do this by installing a plugin. And, luckily, the magnificent Sean Barton (a freelance website developer in Crewe) has produced a free plugin to do just that. It essentially runs Victor M. Font’s function (see above) against every page and post.

You can download the Bye Bye Divi plugin here:
https://www.sean-barton.co.uk/2017/12/bye-bye-divi/

Once downloaded, install and activate it in your WordPress dashboard. You can then load it from the “Settings” menu:

Read the onscreen instructions carefully and, when ready, hit the ‘run’ button. All your redundant Divi shortcodes will be vapourised. And … don’t forget to run a database backup first!