3

I'm searching for half an hour now on how to get the url/permalink base in Wordpress (the 'category' and 'tag' value set in the backend). Could you please point me in the right direction?

I want to dynamically print the following - but only replace the tags and category part (not the tag/category itself):

<a href="/tags/my-tag">My Tag</a>
<a href="/category/my-category">My Category</a>
0

1 Answer 1

9

You really shouldn't need this, as you should be outputting the URLs via the API: get_tag_link, get_category_link, get_term_link.

However, for the sake of answering the question, they're stored in options:

get_option( 'tag_base' );
get_option( 'category_base' );
1
  • The reason is that the name or slug of the tag will be the same in dev/testing and production - but the tag_id will vary! So my thought was, that it is more efficient to just grab the set tag_base and append the slug - other than query the database via get_term_link to get the full url. And with the second option, the slug has to be hard-coded, too. Mar 21, 2013 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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