-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-graphql-secondary-title.php
31 lines (28 loc) · 1.29 KB
/
wp-graphql-secondary-title.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
/**
* Plugin Name: WPGraphQL Generate Secondary Title
* Plugin URI: https://github.com/snibbo71/wp-graphql-secondary-title
* Description: A WPGraphQL Extension that adds the secondary title from the secondary title plugin which must be installed. The secondary title plugin is available from https://en-gb.wordpress.org/plugins/secondary-title/
* Author: Steve Brown
* Author URI: https://www.most-useful.com/
* Version: 1.0.0
*
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/* Note that unless you have Jason Bahl's WPGraphQL WordPress plugin, this will do nothing */
add_action( 'graphql_register_types', function() {
register_graphql_field( 'ContentNode', 'secondaryTitle', [
'type' => 'String',
'description' => 'Adds a secondary title to the tree',
'resolve' => function( \WPGraphQL\Model\Post $post, $args, $context, $info ) {
if ( function_exists('get_secondary_title') ) {
$title = get_secondary_title($post->databaseId);
return $title;
} else {
return 'Secondary Title Plugin Not Installed';
}
},
]);
} );