get_category_link( int|object $category )
Retrieve category link URL.
Contents
Description Description
See also See also
Parameters Parameters
- $category
-
(int|object) (Required) Category ID or object.
Return Return
(string) Link on success, empty string if category does not exist.
Source Source
File: wp-includes/category-template.php
function get_category_link( $category ) {
if ( ! is_object( $category ) ) {
$category = (int) $category;
}
$category = get_term_link( $category );
if ( is_wp_error( $category ) ) {
return '';
}
return $category;
}
Expand full source code Collapse full source code View on Trac
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Category Link
<?php // Get the ID of a given category $category_id = get_cat_ID( 'Category Name' ); // Get the URL of this category $category_link = get_category_link( $category_id ); ?> <!-- Print a link to this category --> <a href="<?php echo esc_url( $category_link ); ?>" title="Category Name">Category Name</a>Worth remembering that a category_id is a term_id and not a term_taxonomy_id
(And, yes, you can figure that out from reading the code. But these sometimes will be the same, fooling some people into thinking that the term_taxonomy_id was right. But sooner or later you will probably get examples where they are different, and then things do not work right.)