Showing results for 
Search instead for 
Did you mean: 

Get Current Product Category Name/ID

Get Current Product Category Name/ID

Hey everyone,

I am brand new to magento 2 so forgive me if this is pretty basic. I am using magento 2.3 and am having issues researching or finding a solution for something that seems super simple. I just need to grab the category name or ID of the current product I am viewing so I can add it to a data attribute in the html.

Only solution I found that worked was using the object manager which I read is a bad thing to do. The other solutions used the registry which is deprecated.

Any help would be appreciated.


Re: Get Current Product Category Name/ID

Hello @beartheset7958 


I hope I have solution for this.

Checkout this articles:

How to Get Current Product in Magento 2

How to Get Current Category in Magento 2


Hope this helps you .