Custom category handler breaks head tags plugin

I am using a custom handler for my site as outlined here: How to remove category prefix from category URLs?, to allow me to remove the /category from my permalinks and still fetch the correct data for the page. This works nicely, however when I pass this custom handler in, the head tags plugin stops working and not head tags data in contained in the API response. I took a look through the source code but couldn’t work out what would be blocking this as I am picking the handlers from the list.

My custom handler in my project: https://github.com/Vizzuality/gfw-blog-headless/blob/develop/packages/gfw-blog/src/index.js#L115.

This affects both archives and single posts when passed in.

Any thoughts welcome!

Hi @e.j.a.brett

I have cloned your project and checking the behaviour of your project locally
Can you explain a bit more the issues you’re having?

Which handler is the one you’re having problems with? The name: 'categoryOrPostType' or the name: 'topTags'?

What do you mean by “stops working”? Is there any specific error you’re getting?

Can you specify some URL’s that can be used to reproduce the issue?

Thanks!

Hi @juanma thanks for checking out the project.

The one I am having issues with is the categoryOrPostType. There are no errors present, however the head tags does not operate as expected. I am using Yoast SEO to configure them on the backend.

I will try to explain to steps to repeat the issue visually.

If you are to load a single post view from the develop branch (with the categoryOrPostType passed in), then the head tags load correctly on first load. If you then navigate away from this post and return to it the head tags are not added to the page. Additionally the head tags are never added on the archive pages for categories or tags.

If you are to checkout this branch from this PR https://github.com/Vizzuality/gfw-blog-headless/pull/26 where I have disabled the custom category handler, the above flow for single posts always adds the head tags. NOTE: on this branch you cannot access the category archive pages as due to the permalink structure breaking this view. This is what the category handler addresses.

In summary: adding a custom handler for the category breaks head tags on single post view when navigating through a link, and completely for archive pages. Without passing it everything works.

I hope that is enough detail! It’s quite hard to show a code example for this one.