Use get_category_link() to get WordPress category url

As category url’s differ based on Permalink settings, when developing WordPress website it’s wise to use dynamic category url , in this case – built in function get_category_link. No matter what Permalink options are get_category_link will output actual link to category. This article will cover possible ways how to use it.

In general, function looks like this:

<?php get_category_link( $category_id ); ?>

where $category_id is actual category’s id which you get witch you get with get_cat_ID function. So all together it looks:

<?php
$category_id = get_cat_ID( 'Category Name' );
get_category_link( $category_id );
?>

If category’s name  might change in the  future, more safe option to get category’s id is to visit /wp-admin/edit-tags.php?taxonomy=category, copy url of category and look for parameter tag_ID, in my case: &tag_ID=5 I. So if  category’s ID is 5, then code will be

<?php get_category_link(5); ?>