The WP function get_category_link()
will do the trick.
/**
* Gets the URL for a category term archive based on the category's slug.
*
* @param string $category_slug The slug of the category to get the category arcive for.
*
* @return string The category (term) archive URL. Empty string on error.
*/
function wpse_get_category_url_by_slug( $category_slug ) {
return get_category_link( get_cat_ID( $category_slug ) );
}
Instead of a creating a wrapper like the example above, you could also just call the WP function directly: get_category_link( get_cat_ID( $category_slug ) )
Related Posts:
- New categories are now going to 404s
- Best way to programmatically link to multiple categories (union/intersection) [closed]
- How to view WordPress’ default category IDs?
- force category base – archive pages work WITH & WITHOUT category base slug in url?
- How to get selected taxonomy or category ID if using custom walker?
- How to set the same base url for two different taxonomies?
- Multiple Parent Category URLs
- Custom EndPoint not working when strip child category in URL
- Is There a Difference Between Taxonomies and Categories?
- How to change permalink structure for custom post type and it’s taxonomies?
- Check if a post is in any child category of a parent category
- How to export and import taxonomies (category, tag and/or custom taxonomy) and their terms
- Remove parent category from permalink? Basically only have the child category?
- Custom permalink structure leads to be 404 on pagination
- How to get permalinks with category base working with sub-categories
- How to display non-hierarchical taxonomy as terms with checkboxes?
- Category archive by year with permalink support /category/YYYY
- get_categories for custom post type with a specific custom taxonomy attached
- Add a URL prefix to permalinks of one category of posts only
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Control term order on a per-post basis
- Could not insert term into the database
- How can I add the featured image functionality to a custom taxonomy?
- Filtering categories in the permalink structure
- Share one taxonomy across multiple blogs in 3.0 [duplicate]
- Allow duplicate permalink slugs for posts in different categories
- Force WordPress to Show Pages Instead of Category
- Can a Child Category Have More than One Parent?
- Combine two taxonomies in a hierarchical tree
- How do I use the same post slug for different Categories?
- Weird behaviour when adding terms/term_taxonomies programmatically
- How to remove category from wordpress url?
- Multiple post categories – single permalink
- How to create a custom url for a category [closed]
- How to add the category ID to admin page
- How can I select a primary category?
- wp_update_nav_menu_item() to insert categories
- How to change the category in URL for posts in multiple categories?
- How to exclude uncategorized from permalink structure /%category%/%postname%/
- How to get the url to tag & category base set by the user?
- Admin Panel – Disable Moving Selected Terms To Top of Metabox
- How to make custom taxonomy check boxes like ‘Categories’
- Create terms when registering taxonomy?
- 404 error on subcategory pages
- Categories’ hierarchy in URL
- How to create non-unique sub-category slugs?
- Changing the category permalink structure
- How to get next previous category in same taxonomy?
- Display only deepest category on a single post?
- How to Include the Parent and Child Category in the Permalink if the Post is Added to Both
- Category links suddenly started giving 404 errors
- Add category to custom post type automatically, using category slug
- Best and Cleanest way to remove /category/ from category permalinks? [duplicate]
- Exclude subcategories from the url
- How to display only the parent category in the permalink
- How to add HTML5 ‘required’ attribute to wp_dropdown_categories() without JavaScripts?
- Root level category, tag, author and archive pages to work
- How to Override default update_count_callback for category
- Wrap a chosen category name with div
- Does WordPress Offer a Way to Find All of the Categories that Don’t Have Children?
- Categories and Tags returning 404 on the sidebar when using ugly permalinks
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- Archive pagination causing 404 with permalinks structure
- Permalinks – Different structures for different categories?
- Plural Category Base Slug On Category Archive Page
- custom permalinks for category archive ( custom base and no parent slug )
- wp_list_categories, Add class to all list items with children
- Getting WordPress custom taxonomy/category?
- On Category page, How can I get the category ID?
- Display empty taxonomy terms with get_terms()
- Return category slug / title from category ID
- WooCommerce change category url and product base
- Connecting WordPress gallery to custom categories (taxonomy)
- How to get the number of child categories a specific parent category has?
- Removing category base form links messes up the parent-child behavior
- Get term by slug in Gutenberg
- What’s the difference between “parent” and “category_parent” in a WP_Term object?
- Update taxonomy value of post type in query
- How to query posts from specific authors and categories using WP_query?
- How to get the depth of a category’s subcategories
- How can I convert some categories to a custom taxonomy?
- Any way to assign Post Categories and Tags to Links?
- Duplicate Category and Page URL loads Category instead of the Page
- Add custom taxonomy under the category title
- Display name of the last child category
- “Reversable” and “Re-useable” Subcategories (or other taxonomic structure)
- Default category link for a custom category is a broken link
- Get multidimensional array that reflects category hierarchy
- Want to hide some categories from the categories meta box in the post editor for the two specific user roles
- How to export/import categories and keep their IDs?
- How to set up Author archives with sub category URL
- Allow dot in wordpress permalinks (only for categories)
- How to use wp_category_checklist()?
- Get the name an the description of a link category
- List Terms in Category
- wordpress wp_list_categories
- Get all sub-categories of a parent category
- Can I use get_adjacent_post for specific categories?
- Random taxonomy category list
- How to filter posts by format and category via url?