Add Google Adsense to specific pages only

Hello,

I got a violation report from Google for my ad because one of the pages it loads on doesn’t have any valuable content (the login/register page).

Is it possible to add the code to specific pages only ie. Login/Register page?
Can I add something here?

add_action( 'wp_head', 'add_head_script' );
function add_head_script() 

This is the code I’m using:

// Google Adsense
add_action( 'wp_head', 'add_head_script' );
function add_head_script(){
?>
<div class="leaderboard" align="center">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sugarfree Gallery Main Page -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-XXXXXXXXXX"
     data-ad-slot="XXXXXXXXXX"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<?php
}

Thank you!

Hello @gebigoma,

Thanks for asking. :slight_smile:

A convenient option to display ads on selective pages/post would be to use plugin like Google Adsense Ads Manager. You can download the plugin from following source. https://wordpress.org/plugins/simplest-adsense-ads-manager/

Hope that helps.

Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.