Featured image of post How to Remove Divi Shortcodes From Content ?

How to Remove Divi Shortcodes From Content ?

[SOLVED]How to Remove Divi Shortcodes From Content

Hello Friends as You know we are learning everyday in our life. so today we will learn how to remove shortcodes from the content while migrating our site.

Problem with Content

when i was migrating the website we got the lots of the divi shortcodes in the content.

when i was researching the solution but i ended up with the plugin that is paid. so me and my colleague decided to solve with PHP script.

This code can be use to Remove Divi shortcodes from the wordpress blogs and Content

put this code in the fucntions.php file

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
global $wpdb;
$allPosts = $wpdb->get_results("SELECT * FROM `wp_posts`");
foreach($allPosts as $post){
  $content = RemoveShortcodes('/\[\/?et_pb.*?\]/', '', $post->post_content);
  $wpdb->update(
    'wp_posts',array('post_content' => $content),array( 'ID' => $post->ID )
  );
}

function RemoveShortcodes($beginning, $end, $string) {
  $beginningPos = strpos($string, $beginning);
  $endPos = strpos($string, $end);
  if ($beginningPos === false || $endPos === false) {return $string;}
  $textToDelete = substr($string, $beginningPos, ($endPos + strlen($end)) - $beginningPos);
  return RemoveShortcodes($beginning, $end, str_replace($textToDelete, '', $string));
}

code credit : https://github.com/vidursingh96



If it is helpful and saves your valuable Time ⏱ please show your support 👇. Buy Me A Coffee
Buy me A Coffee, Thank you and canva ( For Beautiful designs ). Thanks for the reading 👍.
Built with Hugo
Theme Stack designed by Jimmy