When developing a wordpress site we often need to get a category ID from it’s name. Here is a very simple way to get category ID from category name.
First of all, Please paste the below code in your function.php file.

function get_category_id($category_name){
$term = get_term_by('name', $category_name, 'category');
return $term->term_id;

After saving function.php file, You can call this function using any ofย  your category name.Example:

$category_id = get_category_id('Category name');
If you like this article, please consider sharing it!