Last active
August 11, 2021 20:31
-
-
Save 8ctopotamus/730e80bbb4e82913335dbb59e6b92734 to your computer and use it in GitHub Desktop.
Render VSComposer shortcodes to HTML and add to WPGraphQL output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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