The get_linkcatname() WordPress PHP function retrieves the name of a link category by its ID.
Usage
echo get_linkcatname( $category_id );
Example:
echo get_linkcatname( 5 ); // Output: "Technology"
Parameters
- $id (int): The ID of the link category you want to get the name of. If no category is supplied, it defaults to 0.
More information
See WordPress Developer Resources: get_linkcatname
Examples
Display the name of a link category
This code retrieves the name of a link category with the ID 3 and displays it on the page.
$category_id = 3; $category_name = get_linkcatname( $category_id ); echo "Link category name: " . $category_name;
Creating a custom list of link category names
This code creates a custom list of link category names using their IDs.
$categories = array(1, 2, 3); echo "<ul>"; foreach ($categories as $category_id) { $category_name = get_linkcatname( $category_id ); echo "<li>" . $category_name . "</li>"; } echo "</ul>";
Check if a link category exists
This code checks if a link category with a specific ID exists.
$category_id = 4; $category_name = get_linkcatname( $category_id ); if ( !empty( $category_name ) ) { echo "Link category exists."; } else { echo "Link category not found."; }
Display link categories with names containing a specific keyword
This code displays link categories with names containing the keyword “tech” (case-insensitive).
$categories = get_terms( 'link_category' ); $keyword = 'tech'; echo "<ul>"; foreach ( $categories as $category ) { if ( stripos( $category->name, $keyword ) !== false ) { echo "<li>" . $category->name . "</li>"; } } echo "</ul>";
Combine link categories based on their names
This code combines two link categories based on their names and displays the new combined name.
$category_id_1 = 2; $category_id_2 = 3; $category_name_1 = get_linkcatname( $category_id_1 ); $category_name_2 = get_linkcatname( $category_id_2 ); $new_category_name = $category_name_1 . ' & ' . $category_name_2; echo "Combined link category: " . $new_category_name;