WordPress – Display Ads only on posts not on pages

June 15, 2021

Gokul Deepak S

We may want to display ads on our WordPress website. While coming for customization we would be having many troubles.

Target: To show ads only on posts and not on pages

What do we need: WordPress website, Genesis Theme, Genesis Hook plugin

Solution:

  1. Install Genesis Hook Plugin from the plugins repository
  2. Go to Genesis -> Genesis Hook from the side menu in wordpress admin console
  3. Choose the place where you are going to place the ad. Let us consider you want to display the ad below the Header. So paste the below code under Genesis_after_head section
<?php if (!is_page()) {  ?>
<!-- Your Scripts -->
</script>
<?php } ?>

For example we have pasted the google adsense code

<?php if (!is_page()) {  ?>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- GokulDeepak SideBar -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-xxxx62423435"
     data-ad-slot="25xxxxxxxxxxxx"
     data-ad-format="link"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<?php } ?>

About the author

Gokul Deepak is a DevOps engineer focused on building reliable cloud systems through automation, observability, and disciplined infrastructure design. He shares practical insights from real-world production environments, helping engineers build systems that scale with clarity and confidence.

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments