There are functions for retrieving a term/category link (i.e. URL to the term archive page) and in the case of the default category
taxonomy, you can use get_category_link()
:
<a href="https://wordpress.stackexchange.com/questions/361461/<?php echo esc_url( get_category_link( $category[0] ) ); ?>"><?php echo $category[0]->name; ?></a>
For custom taxonomies, you’d use get_term_link()
.
Related Posts:
- How do I get the category URL from get_the_category?
- How do I use the same post slug for different Categories?
- Rewrite rule page url with category
- Create terms when registering taxonomy?
- How to create non-unique sub-category slugs?
- Rewrite category slug
- Using same slug name for a page and category
- Add category to custom post type automatically, using category slug
- I use same slug name for category and page
- Divi change project slug based on category
- Removing the number in a category slug
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- Plural Category Base Slug On Category Archive Page
- Return category slug / title from category ID
- Duplicate Category and Page URL loads Category instead of the Page
- Category slug $_SERVER[‘REQUEST_URI’];
- 403 forbidden on one page only
- Get the name an the description of a link category
- Using a portfolio_category slug in wordpress URL
- Categories vs. Page Site Organization
- WooCommerce duplicate sub categories and product slugs
- Pagination for category slug returns 404 when page >= 2
- Displaying a full post instead of a slug per category?
- wordpress sub-category ( lowercase letters + non-latin characters ) = 404
- The default code for “posts_nav_link” on category.php isn’t working
- Mod_Rewrite to show only last subcategory in URL
- Get posts from specific taxonomy term
- how to get full category path including parent and subcategories
- Automatically redirect a page to a category that share the same slug
- Use the category name instead of category slug in permalinks
- How do I add a tag slug to a category URL to filter posts?
- Change of category structure will cause two kinds of URLs for one post
- Change slug of Standard wp Post category
- How to remove the category from post slug
- Ordering categories by slug vs. name
- Echo Category Nicename
- pagination 404 error, same slug home and categories
- Different post slug based on archive
- A different permalink structure for different categories
- OK to redirect the root WordPress category slug?
- How Can I Use Equal And Question Mark In Category Slug?
- How to remove category name for only one category?
- How to prevent WordPress from redirecting single page to prefixed category archive with same name?
- Include a page’s “category” in its URL
- Using the slug of a custom post category as prefix for the underlying custom post slugs
- Change the full slug for a specific category?
- Get category from slug list
- How to auto update post title and slug with category name when post status is updated
- Hide category name using mod_rewrite
- Show only one of the categories of a post in the breadcrumb?
- hierarchical taxonomy in permalinks? using same slug
- woocommerce – products by category slug? [closed]
- Category slug in in loop always the same?
- How can I get rid of the the category suffix–NOT “prefix” (i.e. foo-1, foo-2, etc)
- How to get category slug link? ( include parent categories)
- How to add custom prefix before category base for category page URL?
- Gutenberg editor add a custom category as wrapper for custom blocks
- Different template for subcategories
- Exclude category by slug for for each loop
- Category Archive, list subcategories of each post
- Disable pagination only for specific category
- Check if post belongs to any category
- Remove Parent Category from Child Category URL
- Allow users to post to a certain category
- How to run select query of post with category and tags for API?
- Populate dropdown based on selection of parent category
- WooCommerce – How to show specific category first-rest of products-specific category last
- Multiple URL’s based on category for one post
- WordPress category check
- How can I improve this taxonomy treating approach?
- How to add current custom taxonomy slug to body class
- Nicer URL for viewing category of posts?
- Get Categories Where Taxonomy Equals ‘n’
- Odd results in get_the_terms vs wp_get_post_terms
- Remove Archive | from Categories
- Only first category!
- How to add meta description, keywords, custom title to a category template
- User level categories
- Exclude category from drop down list form
- Programmatically Create Category and sub Category and sub sub Category
- How to create a table with counts of category combinations?
- How to get the_category(‘, ‘) with link “title” attribute
- product_cat image url from database
- How to get the term id inside the start lvl method of category walker?
- Multiple if statements with else for get_the_category [closed]
- Most efficient way to display current post subcategories?
- How to Query the Top 5 Posts of a specific category?
- How to add a post with new Taxonomy without assigning to default category?
- Query post only from categories that have subcategories
- How to load jquery tag-it plugin into admin?
- Show parent-child relationship for categories in the wordpress admin
- How to assign different categories to pages in wordpress?
- All post of child category not in top category
- How to link ACF relationship field to the new Query block in Full Site Editing
- Function to reference post meta in place of category Woocommerce
- hide_empty property not working when using get_terms
- sub-category showing up in wrong order in breadcrumbs
- Category Redirection Problem
- Hierarchical outline of posts
- How to remove the category from the url only for a specific category of articles on wordpress