Answers for "how to get the category name in wordpress"

PHP
0

how to get category from post id

get_the_category($post->ID)
Posted by: Guest on January-04-2021
0

display category name wordpress

<?php
$categories = get_the_category();
if ( ! empty( $categories ) ) {
	echo '<a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . esc_html( $categories[0]->name ) . '</a>';
}
?>
Posted by: Guest on December-18-2020
1

get the category wp

//get category name foolproof 
echo (!empty(get_the_category($post)) ? get_the_category($post)[0]->name : '');
Posted by: Guest on September-09-2021

Code answers related to "how to get the category name in wordpress"

Browse Popular Code Answers by Language