In my footer I have hard coded the links and would like to link some to there category, I could just copy the full URL to it and paste in the href="" but I would rather call it using php.

My knowledge of WordPress and PHP is little and I have tried searching for something that will do this but none work, my last go used this:

<a href="<?php echo get_permalink( get_page_by_path( 'cooking-sauces' ) ); ?>">Cooking Sauces</a>

and I tried this:

<a href="<?php echo get_permalink( get_page_by_path( 'cooking-sauces')->ID); ?>">Cooking Sauces</a>

but did not work.

So the full URL would be http://woloped.co.uk/blog/products/cooking-sauces/

Please can some one help, many thanks Dave

UPDATE: Could it be called using the SLUG and if yes have is this done please.


1 Answer 1


The "page" in WordPress usually refers to a "PAGE page", as in only post of page post type. Not any page of the site in general.

What you want to link to is category archive. Something along this should work:

echo get_category_link( 'cooking-sauces' );

If cooking-sauces is slug of a term that belongs to custom taxonomy (as opposed to native category taxonomy) you will probably need to use something like:

echo get_term_link( 'cooking-sauces', 'your-taxonomy-slug' );
  • Hi @Rarst Thanks for your reply and it kind of worked as I have one category that was create in the admin under Posts > Categories, however the categories I want to link to are part of the products section that is built into the theme so there is a tab for products and there you add the product categories so Cooking Sauces link is woloped.co.uk/blog/products/cooking-sauces I did try echo get_category_link( get_category_by_slug( 'products/cooking-sauces' ) ); but did not work.
    – Dave
    Jul 16, 2013 at 11:02
  • yes it worked and a great big thankyou
    – Dave
    Jul 16, 2013 at 11:51
  • @Dave you are welcome :) if this answers your question please mark it as accepted answer (green check mark) so that system recognizes thread as resolved
    – Rarst
    Jul 16, 2013 at 12:06
  • i can't find a green check box anywhere to mark this a resolved ???
    – Dave
    Jul 16, 2013 at 13:08
  • @Dave well, grey originally :) to the left of the answer, under voting score and arrows
    – Rarst
    Jul 16, 2013 at 13:14

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.