Canonical URL API

#211884
  • Resolved Yannick Forest
    Rank Math free

    My use-case is I need to set the canonical REL of a page to an external URL value that I can only obtain programmatically. However, when I add a filter with the intent of inserting a canonical URL link on a page using the RankMath API, nothing changes in the post_meta. The only time a canonical value is added to post_meta is when you change one manually. Am I missing something, or is that API useless (for my use case)? It sure isn’t properly described in the docs — i.e., you need to already have a custom canonical value set for the filter to work.

Viewing 1 replies (of 1 total)
  • Ankit
    Rank Math business

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    You can use the following filter and add your condition inside it.

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    
    //You can call your outside canonical link function 
    //and check if on product page you want to show the modified URL
    
            if(is_product()){
                return ''; //you can return that url slug here.
            }
    		
    	return $canonical;
    });

    I hope that helps. Thank you, and looking forward to your update.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Canonical URL API’ is closed to new replies.