0

I have the following code appending an ad block at the end of my posts

function info_after_post($content){
if (is_single()) {
$content .= 'AD CODE';
}
return $content;
}
add_filter( 'the_content', 'info_after_post' );

I'd like somehow exclude this from executing on post category ID 71 while still executing for all my other post categories and I can't quite figure out how.

I tried this, but couldn't tell if I was going down the right path.

function info_after_post($content){
if (is_category( '71' )) {
    $content ;
} else { 
    $content .= 'AD CODE';
}
return $content;
}
add_filter( 'the_content', 'info_after_post' );

Much thanks for any help on this!

1

I think has_category() should help you.

function info_after_post($content){
if (is_single() && ! has_category(71)) {
$content .= 'AD CODE';
}
return $content;
}
add_filter( 'the_content', 'info_after_post' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.