How to get and display canonical text via code

#280847
  • Resolved Sewing Expert
    Rank Math free

    Hi,
    how to get the custom canonical text of a specific URL (that we set in advance tab of )

    as you can see on this Heater Category Page

    On the very top, you can see the page title as Heater price in Pakistan (it is good for SEO).
    just below it, I have set the canonical text as Heaters (as by default it was displaying page title there).

    now I want to get this canonical text from code (using my funcation.php of WordPress).

    please guide how to do it,

    EG: $product->get_type();
    is there some fucnation like $product->get_canonical_text() ? if now, please suggest alterative to getch that text from db

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting Rank Math today.

    If you changed the canonical tag of the page with the help of Rank Math you can retrieve it with the following function:

    
    $custom_canonical = get_post_meta(get_queried_object_id(), 'rank_math_canonical_url', true);
    

    Having said that, it seems that you didn’t set a custom canonical tag so this function should return null as by default our plugin sets the canonical equal to the page URL.
    ​​​​​​
    Hope this helps clarify your doubts and solve your issues.

    Don’t hesitate to get in touch if you have any other questions.

    got it, Thanks alot.

    Hello,

    We are super happy that your issue is resolved. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘How to get and display canonical text via code’ is closed to new replies.