Render Visual Composer shortcode in wordPress

0
1509

Add the below code in your Activated theme functions.php

To register the VC shortcodes the following must be called:

WPBMap::addAllMappedShortcodes();
Here is an example how to render the VC shortcodes on the content of a post:

add_action( 'rest_api_init', function ()
{
   register_rest_field(
          'page',
          'content',
          array(
                 'get_callback'    => 'compasshb_do_shortcodes',
                 'update_callback' => null,
                 'schema'          => null,
          )
       );
});

function compasshb_do_shortcodes( $object, $field_name, $request )
{
   WPBMap::addAllMappedShortcodes(); // This does all the work

   global $post;
   $post = get_post ($object['id']);
   $output['rendered'] = apply_filters( 'the_content', $post->post_content );

   return $output;
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here