How to parse shortcodes within returned content
Here’s the code given by the VC team. And it works.
// display content in grid
add_filter( 'vc_grid_item_shortcodes', 'my_module_add_grid_shortcodes' );
function my_module_add_grid_shortcodes( $shortcodes ) {
$shortcodes['vc_post_content'] = array(
'name' => __( 'Post content', 'fluidtopics' ),
'base' => 'vc_post_content',
'category' => __( 'Content', 'fluidtopics' ),
'description' => __( 'Show current post content', 'fluidtopics' ),
'post_type' => Vc_Grid_Item_Editor::postType(),
);
return $shortcodes;
}
add_shortcode( 'vc_post_content', 'vc_post_content_render' );
function vc_post_content_render() {
return '{{ do_shortcode_post_content }}';
}
add_filter( 'vc_gitem_template_attribute_do_shortcode_post_content', 'vc_gitem_template_attribute_do_shortcode_post_content', 10, 2 );
function vc_gitem_template_attribute_do_shortcode_post_content( $value, $data ) {
/**
* @var null|Wp_Post $post ;
* @var string $data ;
*/
extract( array_merge( array(
'post' => null,
'data' => '',
), $data ) );
$atts_extended = array();
parse_str( $data, $atts_extended );
WPBMap::addAllMappedShortcodes();
$output = do_shortcode( $post->post_content );
ob_start();
// do_action( 'wp_enqueue_scripts' );
// wp_print_styles();
// wp_print_scripts();
// wp_print_footer_scripts();
$output .= ob_get_clean();
return $output;
}