Skip to content

Instantly share code, notes, and snippets.

@vanpariyar
Created January 18, 2022 14:32
Show Gist options
  • Select an option

  • Save vanpariyar/34a2c969e2ed63fb1d8c0f425e6c133a to your computer and use it in GitHub Desktop.

Select an option

Save vanpariyar/34a2c969e2ed63fb1d8c0f425e6c133a to your computer and use it in GitHub Desktop.
Remove Divi shortcodes from the wordpress blogs and Content

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

put this code in the fucntions.php file

<?php
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment