-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin only returns fields that were overridden, not the Yoast defaults #3
Comments
Okay, so I did a really dirty hack to add some metatags values to the REST output. (Only the ones I needed and care about mostly). I had to extend and overrides some Yoast core classes to be able to get some values instead of writing them to HTML document. It seems like there is a lot to do to improve Yoast developer-friendly usability. |
@leup thanks a lot for your contribution. I've been trying to add the yoast title for the categories and the tags, but I haven't been able to make it work yet. Do you think you could help me? I've been trying here wp-pwa@bbc11e8
|
@Poliuk I would very much like to help you but I am overflowing with job right now and it could take (a lot of) days before I got any spare time. |
@leup Thanks for your prompt answer 😊 I'll keep trying to finish my part, I'll let you know :) |
Finally found the way, I'll post it here just in case someone lands in this issue: // Category
register_rest_field( 'category',
'yoast',
array(
'get_callback' => array( $this, 'wp_api_encode_yoast_category' ),
'update_callback' => null,
'schema' => null,
)
);
// Tag
register_rest_field( 'tag',
'yoast',
array(
'get_callback' => array( $this, 'wp_api_encode_yoast_tag' ),
'update_callback' => null,
'schema' => null,
)
); function wp_api_encode_taxonomy (){
include __DIR__ . '/classes/class-frontend.php';
$wpseo_frontend = WPAPI_WPSEO_Frontend::get_instance();
$yoastMeta = array(
'yoast_wpseo_title' => $wpseo_frontend->get_taxonomy_title(),
'yoast_wpseo_metadesc' => $wpseo_frontend->metadesc(false),
);
return (array) $yoastMeta;
}
function wp_api_encode_yoast_category($category) {
$args=array(
'cat' => $category['id'],
);
$GLOBALS['wp_query'] = new WP_Query( $args );
return $this->wp_api_encode_taxonomy();
}
function wp_api_encode_yoast_tag($tag){
$args=array(
'tag_id' => $tag['id'],
);
$GLOBALS['wp_query'] = new WP_Query( $args );
return $this->wp_api_encode_taxonomy();
} |
See #5 for a nicely laid out solution to this issue. |
I know that this plugin hasn't been tested with this version of WP, but I thought I'd post this in case you plan on updating. Yoast itself has vague plans to support the WP REST API themselves, but no timeline that I can see. Yoast/wordpress-seo#3061
What's happening
Yoast data is coming back empty for every field.
What's Expected
The Yoast fields should contain the values the plugin would normally add to the HEAD of the document.
If I override the defaults in the Yoast plugin on the page, then the new value shows up.
The text was updated successfully, but these errors were encountered: