Skip to content

Shortcodes from Visual Composer #12

@web86

Description

@web86

Hello! My posts are made with WpBakery (Visual Composer), so when I get them in WpGraphQL via wp-graphql-content-blocks I get a lot of not rendered shortcodes in output.

I solved this for content field, I registered a new field called "vsCodeShortcodesToHTML" and get there all decoded content. Then in my React component I just use this field instead of "content". To do so I added this code in my function,js:

// render js composer shortcodes to html in graphql response "addAllMappedShortcodes" field
add_action('graphql_register_types', function() {
	function vsCodeShortcodesToHTML( $post ) {
		if(class_exists('WPBMap') && method_exists('WPBMap', 'addAllMappedShortcodes')) {
			WPBMap::addAllMappedShortcodes(); 
		}
		return do_shortcode(get_post($post->ID)->post_content);
	}
	register_graphql_field('Post', 'vsComposerContentRendered', [
		'type' => 'String',
		'description' => __('the_content() VS Composer shortcodes rendered to HTML.', 'wp-graphql'),
		'resolve' => 'vsCodeShortcodesToHTML'
	]);
	register_graphql_field('Page', 'vsComposerContentRendered', [
		'type' => 'String',
		'description' => __('the_content() VS Composer shortcodes rendered to HTML.', 'wp-graphql'),
		'resolve' => 'vsCodeShortcodesToHTML'
	]);
	
});

It works for me untill I want to brake the content into blocks with your plugin. Shortcodes are still remaining.
Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions