Lien de la méthode : https://www.seomix.fr/wordpress-recuperez-lid-dune-categorie/
$category = get_the_category();
$mycat = $category[0]->cat_name;
$mycat2 = get_cat_id($mycat);
Utilisez ensuite la variable $mycat2 comme bon vous semble. Attention, le code est a utiliser dans le loop de WordPress.
Comment utiliser l’ID de catégorie
AFFICHER L’ID EN DUR
<?php echo get_cat_name($mycat2);?>
LE LIEN DE LA CATÉGORIE
<?php get_category_link($mycat2);?>
LE LIEN DE LA CLE FLUX RSS DE LA CATÉGORIE
<<?php get_category_feed_link('$mycat2', ''); ?>