I implemented state.source.entity() this way because for me it wasn’t clear how to know the type of an entity depending on the given link but I didn’t realize it is the same case as state.source.data!
This means that if you are using Yoast ^14.0, you should use this new package . And, if you’re using a previous version where the REST API is not supported by the Yoast plugin, or you use other SEO plugin, you can use the @frontity/head-tags package.
Revisiting this thread, I think I forgot something important to mention!
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, you would need to include some code in your WordPress site similar to the following one:
That code adds the type inside the _links field of post entities and makes it embeddable so type entities are included when Frontity makes calls to the WordPress REST API.
I’m trying to use the transformLinks.base property but it doesn’t seem to work, and when I tried to find in the code how that is working, I couldn’t find where that transformation is being done. Could you help me here?
The @frontity/yoast package transforms links inside the useYoastHead hook, defined in /src/hooks/index.ts:
The function transformAllLinks() is defined in /src/utils/index.ts and uses transformLink() – defined in the @frontity/head-tags package – under the hood.
The property state.yoast.transformLinks.base is not documented yet but it is explained in the TSDocs:
WordPress URL base that must be replaced by the Frontity URL base (specified in state.frontity.url). If this value is not set, it is computed from state.source.api.
What’s exactly the problem you have? Is there a way to reproduce it?
I’ve just noticed that we are not saying anything in the Readme about the snippet that needs to be added in PHP, this one: Support for Yoast plugin REST API fields.
Do you guys think that it makes sense to say in the docs that in the future that snippet will be included in the Frontity WordPress Plugin? Or is it better not to mention the Frontity WordPress Plugin?
I don’t completely understand what you’re saying in this post.
By “post types” do you mean Custom Post Types? I can’t find any other reference to the yoast_meta field. Can you explain what that is.
When you refer to “the homepage or the archive of a custom post type” are you intending “homepage” and “archive” to mean the same thing, or are they different things?
I’m also not sure what this means: " That code adds the type inside the _links field of post entities".
It would be great if you could provide more clarity here.
When I said homepage I was refering to the the archive of posts, which is usually the homepage. It could be rephrased as “the archive of posts, or the archive of a custom post type”.
Those archives are like categories or tags, but the entity with the name, description, and so on, is returned by the types endpoint (as mentioned before).
I’m not sure if that way is more clear or not.
In the entities that the WP REST API returns, there is a field called _links that basically links it with other related entities (more info here). Those links make the linked entity to be included when using the _embed=true query param.
In this case, when any post is requested using _embed=true, the post type entity is embedded as well and populated in the frontity store. That way, you don’t have to do a different request to get the post type entity. Something similar happens with categories and tags, but those are linked by default.
By the way, the specific code that adds the link is this one:
I think it’s better not to do references to things that are not available for the user.
In the meantime, I’ve opened this issue so we can add notes of those things we’d like to add to the documentation referencing to the Embedded Mode (or the Frontity plugin, that I understand it’s the same thing) once that documentation is available