get_category_link( int|object $category )

Retrieves category link URL.

Description

See also

Parameters

$category

(int|object) (Required) Category ID or object.

Return

(string) Link on success, empty string if category does not exist.

More Information

This function 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.

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;
}

Changelog

Version Description
1.0.0 Introduced.

© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_category_link