WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get category link

Description

Returns the correct url for a given Category ID.

In a Plugin or Theme, it can be used as early as the setup_theme Action. Any earlier usage, including plugins_loaded, generates a Fatal Error.

Usage

<?php get_category_link$category_id ); ?> 

Parameters

$category_id
(integer) (required) The category ID whose link will be retrieved.
Default: None

Return Values

(URL) 
(string) URL with a link to the category.

Examples

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>

Notes

Change Log

Since: 1.0.0

Source File

get_category_link() is located in wp-includes/category-template.php.

Related

See also index of Function Reference and index of Template Tags.