add_filter for changing canonical not working in page template

[ad_1]

Hi,

I have a custom page template for products (see link) which is shown for any url like “/products/”. I use add_action( ‘template_include’) to redirect these URLs to the template file. In the template file I use the following filters to change the metadata so they do not default to the blog page metadata:

add_filter(‘pre_get_document_title’)
add_filter( ‘rank_math/frontend/title’)
add_filter( ‘rank_math/frontend/description’)
add_filter( ‘rank_math/frontend/canonical’)
add_filter( ‘rank_math/opengraph/url’)

All of them work correctly except the canonical filter, which is still showing a canonical of the blog page. I suspect this is because the filter is applied earlier in the loop. Can you confirm this?

How can I fix this? Is it a bug?

The page I need help with: [log in to see the link]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer