There’s no easy way to migrate from one shortcode system to another, such as WPBakery to Avada, or using Divi and trying to move it over to Gutenberg. I wrote a simple script to take the basic WPBakery shortcodes and output them as plain text, hopefully saving you a bit of time in migrating old posts over to a new system. It covers the following three shortcodes.
- vc_single_image
- vc_column
- vc_column_text
- heading
It’s rough, but it works, and gives you some semblance of a working site. I used it in conjunction with another plugin, “Remove Orphan Shortcodes“, in order to completely move hundreds of posts from using the original WPBakery shortcode system over to Avada, without actually doing a large amount of heavy lifting. What it will do is process nested shortcodes (images within column as an example) and output columns with some margins. Much tweaking to this is possible.
Add this content to your functions.php and fix your WPBakery woes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
function vc_single_image_shortcode($atts = [], $content = null, $tag = '') { // normalize attribute keys, lowercase $atts = array_change_key_case((array)$atts, CASE_LOWER); if ($atts['image']) { $image = $atts['image']; } else { $image = ""; } if ($atts['link']) { $link = $atts['link']; } else { $link = ""; } if ($image !== "") { // actually has to get the image attachment $url = wp_get_attachment_image_src($image, 'large'); // start output $o = ''; $o .= '<a href="'.$link.'" class="figure-image " target="_blank">'; $o .= '<img width="250" height="150" src="'.$url[0].'">'; $o .= '</a>'; $o .= ''; } // return output return $o; } function vc_column_shortcode($atts = [], $content = null, $tag = '') { // normalize attribute keys, lowercase $atts = array_change_key_case((array)$atts, CASE_LOWER); if ($atts['width']) { $width = $atts['width']; } else { $width = "100%"; } if ($width !== "") { if ($width == "1/4") $percentage = "24"; if ($width == "1/2") $percentage = "49"; if ($width == "3/4") $percentage = "74"; // start output $o = ''; $o .= '<div style="width: '.$percentage.'%; margin-right:1%; float:left; display:inline-block;">'; $o .= do_shortcode($content); $o .= '</div>'; $o .= ''; } // return output return $o; } function vc_heading($atts = [], $content = null, $tag = '') { // normalize attribute keys, lowercase $atts = array_change_key_case((array)$atts, CASE_LOWER); if ($atts['header_type']) { $header_type = $atts['header_type']; } else { $header_type = "h1"; } if ($atts['header_align']) { $header_align = $atts['header_align']; } else { $header_align = "left"; } if ($atts['margin_top']) { $margin_top = $atts['margin_top']; } else { $margin_top = "10"; } if ($atts['margin_bottom']) { $margin_bottom = $atts['margin_bottom']; } else { $margin_bottom = "10"; } // start output $o = ''; $o .= '<'.$header_type.' style="text-align: '.$header_align.'; margin-top: '.$margin_top.'px; margin-bottom: '.$margin_bottom.'px; ">'; $o .= $content; $o .= '</'.$header_type.'>'; $o .= ''; // return output return $o; } function vc_column_text_shortcode($atts = [], $content = null, $tag = '') { //basically just spits out the original content. $atts = array_change_key_case((array)$atts, CASE_LOWER); // start output $o = ''; $o .= do_shortcode($content); $o .= ''; // return output return $o; } function wp_shortcodes_init() { add_shortcode('vc_single_image', 'vc_single_image_shortcode'); add_shortcode('vc_column', 'vc_column_shortcode'); add_shortcode('vc_column_text', 'vc_column_text_shortcode'); add_shortcode('heading', 'vc_heading'); } add_action('init', 'wp_shortcodes_init'); |
Leave a Comment