Skip to content

Instantly share code, notes, and snippets.

@8ctopotamus
Last active August 11, 2021 20:31
Show Gist options
  • Save 8ctopotamus/730e80bbb4e82913335dbb59e6b92734 to your computer and use it in GitHub Desktop.
Save 8ctopotamus/730e80bbb4e82913335dbb59e6b92734 to your computer and use it in GitHub Desktop.
Render VSComposer shortcodes to HTML and add to WPGraphQL output.
// add to functions.php or a plugin.
// render js composer shortcodes to html in graphql response
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'
]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment