0

I Need to disable/block the header banner (Adsense code) on specific posts. I'm not a developer, I manually added the script in the header.php. Is there any way to disable that banner by specific post IDs? I would really appreciate any help I get in this matter.

0

You can make the banner unavailable to certain posts by using if condition.

$post_id = get_the_ID();
if ($post_id != idwheredisabled || $post_id != id2wheredisabled || .... ){
    Adsense code
}

if there are many ids then you can load them into an array and check if exists in array.

  • Thanks for responding Akshat! I would love to try this but where do I add this code?? I mean in the header.php or function.php? Sorry as I mentioned above I have no knowledge of PHP whatsoever. – John D Jun 18 '18 at 7:57
  • As you mentioned in the question that you have placed the adsense code in header so you need to put this in header.php. you can replace idwheredisabled and id2wheredisabled with the id's where you want to exclude and .... if you want to add more post ids the you need to use $post_id != id3wheredisabled and so on. – Akshat Jun 18 '18 at 10:11
  • Thanks a ton for explaining! I'll try the code and let you know if it works. – John D Jun 18 '18 at 12:40
  • Hi again, I just tried it but it seems like I must have misunderstood something. '$post_id = get_the_ID(); if ($post_id != idwheredisabled || $post_id != id2wheredisabled || .... ){ Adsense code }' in that code "Adsense Code" part I used the adsense code i use in the header.. Did I do something wrong? – John D Jun 18 '18 at 12:55
  • did you replaced idwheredisabled and id2wheredisabled with the post id where you want to exclude? and " || .... " is not proper code, you should use it if there are more id's if not then no. – Akshat Jun 18 '18 at 13:17

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.