Site logo

Archived topic

has_category()

3 replies · Started by Jeffrey on December 7, 2019

Viewing posts 1–4 of 4

Hello,

I'm trying to add a certain code above my <h1> if the post has a certain category, but I can't get it to work for some reason. Can anyone help me out?

if ( has_category( 'cm1' ) ) {
add_action( 'generate_before_content', 'test' );
function test() {
echo do_shortcode( '<p>testsss</p>' );
}
}

Hi there,

What if you add the if statement inside the function?

YES! That worked!Thank you so much!

No problem :)

This archived topic is closed to new replies.