OPENING POST
Description
Since version 14.0, Yoast added a REST API field where it shows the head tags needed for SEO purposes, so it’d be great to have a package similar to @frontity/head-tags
that fetch the head tags from Yoast field instead of from our plugin.
This way, Yoast team would take care of the REST API support (as they are already doing) and we just have to take care of adapting that info for Frontity with this package.
With this solution, if you use Yoast ^14.0 (the version where they added the REST API support), you could use @frontity/yoast
package and, if you use an older version of the plugin, or any other plugin without API support, you can use the Head Tags plugin & @frontity/head-tags
solution.
Although the Head Tags plugin is working great, users have to install another plugin, so this would mean one plugin less, just with Yoast is enough.
Possible solution
This package could be pretty similar to the @frontity/head-tags
package, as it’s going to do the same, but getting the info that the Yoast plugin is showing in the REST API.
We had another conversation about how it works at this topic. The Yoast plugin is adding a new field to the REST API named yoast_head
, which is a string of all the meta tags (it’s similar to what we’re doing with the REST API Head Tags plugin , but we are adding an array instead of a string). This way, if you go to a post, a category, a tag, etc, in the REST API, you can find this new field with all the meta tag of the specific entity. So if I go to https://myweb.com/wp-json/wp/v2/posts?slug=my-post
, I can find this string:
Apart from this, in the WordPress side, we would need to add the types
endpoint to _links
with embeddable: true
to make sure that information is retrieved in a single fetch when you request a post-type archive using ?_embed=true
. This how we do it in the head-tags plugin. The Yoast team has opened this ticket to add it to WordPress core, but we could add it manually meanwhile or in the future Frontity plugin.
SUMMARY
Please, bear in mind that this section wasn’t part of the opening post. It has been added afterwards and its purpose is to keep a quick summary with the most relevant information about this FD at the top of the thread.
Final implementation
Relevant information
- Demo.
- In order to embed the post types – which are the entities that contain the
yoast_meta
field for post type archives (i.e. the homepage or the archive of a custom post type) – in the REST API responses, users should add a PHP Snippet as explained here. - This package only applies for Yoast ^14.0.0. For previous version take a look at the Head Tags plugin.