-
-
Save webwidely/875caa628140aabe6b5e6cb5e256e4f4 to your computer and use it in GitHub Desktop.
Extender WPGraphQL
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
<?php | |
/** | |
* Plugin Name: GraphQL Example | |
* Textdomain: graphqlexample | |
*/ | |
/** | |
* Add logo and favicon images url to graphql schema in the rootquery. copy file into wp-content/plugins and then activate from Plugin's page. | |
**/ | |
function get_logo() | |
{ | |
$custom_logo_id = get_theme_mod('custom_logo'); | |
$image = wp_get_attachment_image_src($custom_logo_id, 'full'); | |
return $image[0]; | |
} | |
function get_favicon() | |
{ | |
return get_site_icon_url(32); | |
} | |
add_action('graphql_register_types', 'example_extend_wpgraphql_schema'); | |
function example_extend_wpgraphql_schema() | |
{ | |
register_graphql_field('RootQuery', 'logoUrl', [ | |
'type' => 'String', | |
'description' => __('Show logo image', 'graphqlexample'), | |
'resolve' => function () { | |
return get_logo(); | |
} | |
]); | |
register_graphql_field('RootQuery', 'faviconUrl', [ | |
'type' => 'String', | |
'description' => __('Show favicon', 'graphqlexample'), | |
'resolve' => function () { | |
return get_favicon(); | |
} | |
]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment