I want to remove category ids from category URLs and replace them with the current category or subcategory name.
Is this possible?
Any help will be appreciated.
I think you don't need to replace it programmatically. Please check the admin settings.
After updating them, you have to flush the caches and run the reindex.