In my WordPress website i made this code in header.php that write html under the header only if you are on a specific post (product) page,
<?php
$post = get_post();
if ( $post->ID == 'postid' ){
echo '<div>
<p>'text'
</p>
</div>
</div>
</div>';
}
?>
I would like to make the same thing in a specific category page doing something like this
<?php
$postcat = get_the_category();
if ( $postcat->ID == 'categoryid'){{
echo '<div>
<p>'text'
</p>
</div>
</div>
</div>';
}
?>
But it doesn’t work, i also tried different method like
<?php if (is_category('categoryname')) : ?>
<div></div>
?php endif;?>
How can i do this?
Thanks.
2
Answers
You can use
is_product_category
. check the below code.USEFUL LINKE
If post = specific ID
Is post has category "supercat"
For products , check Bhautik’s answer