Last Updated: February 25, 2016
·
1.854K
· dscotts3

Get permalink for category by category name

This function will allow you to pass in a name of a category as the first paramater which will then echo out the link. If you set the second paramater to false, it will return the permalink to the category.

function get_category_link_by_name( $category, $echo = true ) {
    // Get the ID of a given category
    $category_id = get_cat_ID( $category );

    // Get the URL of this category
    $category_link = get_category_link( $category_id );

    if ( $echo ) : 
        echo $category_link;
    else :
        return $category_link;
    endif;  
}