How to get Product Canonical Url by id Programmatically Magento 2?

Get Product Canonical URL in Magento using product id to see your current store product page Canonical URL.

Fetch Product Object by the id and use the method getUrlInStore() to retrieve URL.

Check given code to retrieve canonical URL,

The Output will display the Product Canonical Url in the current store.

Using This way, You can achieve Page Canonical URL for the current store.

Leave a Reply