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
- How to display non-hierarchical taxonomy as terms with checkboxes?
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Combine two taxonomies in a hierarchical tree
- How to remove category from wordpress url?
- How to create a custom url for a category [closed]
- How can I select a primary category?
- How to change the category in URL for posts in multiple categories?
- How to Override default update_count_callback for category
- Categories and Tags returning 404 on the sidebar when using ugly permalinks
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- Plural Category Base Slug On Category Archive Page
- On Category page, How can I get the category ID?
- How to get the number of child categories a specific parent category has?
- Removing category base form links messes up the parent-child behavior
- How can I convert some categories to a custom taxonomy?
- Any way to assign Post Categories and Tags to Links?
- 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
- How to use wp_category_checklist()?
- Get the name an the description of a link category
- Get all sub-categories of a parent category
- Random taxonomy category list
- Specifying multiple categories in URL (permalink)?
- Linking products to categories
- Add “page-a” slug to category link if user visit category link from “page-a”
- Redirect category to url with /category
- Changing permalink from /postname/ to category/postname/
- Change existing taxonomy settings when using custom taxonomy
- category filter doesn’t work in WPML
- One Specific Category To Permalink
- Permalinks: display just one kind of wp category in the posts url
- Multiple URL’s based on category for one post
- category permalinks
- Filtering *out* a taxonomy from the admin post list
- category image taxonomy
- How can I improve this taxonomy treating approach?
- How to add a post without assigning to a category?
- Display custom taxonomy attached to the post on post single page
- How to display parents category and child category separately for a specific post?
- Admin: Navigation Menus do not show empty categories/taxonomies in the list’s search tab
- How to display a value inside a post with a specified category from a category custom field? [closed]
- Echo text using is_tag
- Cannon see subcategory in permalink
- Redirect Changed Permalink on wordpress
- Grandchild Term Things Grandfather Term is It’s Parent
- How do I change the category permalink structure?
- Get posts of a custom post type from category from taxonomy?
- Same menu for different taxonomies to reach different content
- Change categories count to include media attachments
- Anchor tag generates blank href attribute using echo esc_url( )
- How could I write a get_categories_by_year() function?
- Get posts in a subcategory of a chosen parent
- Advanced permalinks structure
- Natural sort / ordering wp_dropdown_categories
- Best way to categorize/populate a magazine style layout
- separate posts to have (kind of) 2 blogs?
- can I ‘combine’ categories as a menu item?
- Displaying posts of given category
- Subcategory Page URL to Display Only Posts from that Subcategory?
- Automatically adding tags and categories into Post Excerpt for searching
- How can i add service category here? [duplicate]
- Show subChild categories
- WordPress 5.4 and higher: Filter posts by category 1 AND category 2 in API requests
- Limit categories to hierarchal depth of 2
- Get multiple category names from permalink
- Show the parent taxonomy by creating shortcode in woocommerce?
- Linking to the most recent post in my podcast category
- WordPress Portofolio Conditional Templating – functions php
- Parent Category and Subcategory default text generated with category
- Get WooCommerce product category list in functions.php
- Include a page’s “category” in its URL
- Post List by category and under custom taxonomy
- Creating a linkable category list with post count
- Remove base category gives 404 error
- Custom permalink /%category%/%postname%/ produces 404 on each post
- Create duplicate category page with content variations
- Renaming default category taxonomy?
- WordPress Category url redirects to subdomain
- How to add a post with new Taxonomy without assigning to default category?
- Page Type with Category Link
- Problem importing categories and sub-categories
- Using pagination with multiple loops causes it to break
- list taxonomy based on taxonomy
- Create custom Perma link
- Show parent-child relationship for categories in the wordpress admin
- Order Categories by Character Count
- Remove “?category=” in the URL wordpress ajax filter work for category
- hide_empty property not working when using get_terms
- Add custom fields to Woocommerce Category Page
- How to remove the category from the url only for a specific category of articles on wordpress
- How to make /category/ URL load properly instead of 404 error?