get_category_link() WordPress Function

The get_category_link() function is used to get the link to a category in WordPress. This function is useful when you need to get the link to a specific category, or when you need to get the link to a category by its slug or id.

get_category_link( int|object $category ) #

Retrieves category link URL.


Description

Top ↑

See also


Top ↑

Parameters

$category

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


Top ↑

Return

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


Top ↑

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.


Top ↑

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


Top ↑

Changelog

Changelog
VersionDescription
1.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.