WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a URL - http://localhost/products/product-name/ and I want to use this URL to retrieve the title Product Name

This is out of loop, so the URL provided is all I have to work from. Product Name is obviously the name of the term, which has the URL http://localhost/products/product-name/ I just need it so I can print it out on a particular place on the website.

The url above denotes the taxonomy as products but this is a rewrite of product_type - I'm not sure if this'll affect the solution.

share|improve this question
My Work Around at the moment, is to run a str_replace on the slug, which I retrieved by regex - then force Capitalize in CSS. Not ideal, but serves the idea well enough. The issue with this method is if the Slug is different to the page title. – Dan Hanly Oct 11 '12 at 10:52

This is far from trivial. URL processing is not straightforward and mostly buried in WP->parse_request() which is not popular to reuse.

There is more useful url_to_postid() function, but it's limited to posts and does not process URL to other things.

If really necessary this would take fork of that function to deal with terms. However more practical solution would probably be to pass some extra data in some form and don't mess with URL at all.

share|improve this answer
I can extract the slug from the URL, as I have done with simple regex - all the links on my site follow a strict pattern, so errors are unlikely. I would have assumed I'd be able to return the rewrite slug of the terms if I returned the entire taxonomy - I could then use this to compare against. – Dan Hanly Oct 12 '12 at 13:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.