Skip to content

Instantly share code, notes, and snippets.

@ashtonlance
Forked from mlipscombe/functions.php
Created March 10, 2022 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashtonlance/a860d51f11a115756ab9dc38a5614339 to your computer and use it in GitHub Desktop.
Save ashtonlance/a860d51f11a115756ab9dc38a5614339 to your computer and use it in GitHub Desktop.
Render Elementor-styled content in WP-GraphQL
add_action('graphql_register_types', function() {
$post_types = WPGraphQL::$allowed_post_types;
if (!empty($post_types) && is_array($post_types)) {
foreach($post_types as $post_type) {
$post_type_object = get_post_type_object($post_type);
register_graphql_field($post_type_object->graphql_single_name, 'styledContent', [
'type' => 'String',
'description' => __('The styled elementor content of the page', 'cottontailpress-headless'),
'resolve' => function($post) {
$content = '';
if (class_exists('\Elementor\Plugin')) {
error_log('class_exists');
$plugin = \Elementor\Plugin::instance();
$content = $plugin->frontend->get_builder_content($post->ID, true);
}
return $content;
}
]);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment