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;
}
Written by Dwight Scott
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#