Do this code on category-archive
template.
- Fetch queried object using
get_queried_object()
. - Check if the parent value in returned object is 0 or not.
-
If it is not 0 then run your code.
$category = get_queried_object(); if($category->parent != 0){ //write your code here }