Put a link to a category round a hard coded A HREF

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="https://wordpress.stackexchange.com/questions/106251/<?php echo get_permalink( get_page_by_path("cooking-sauces' ) ); ?>">Cooking Sauces</a>

and I tried this:

<a href="https://wordpress.stackexchange.com/questions/106251/<?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' );

Leave a Comment