exclude last wordpress blogpost

I want to disable ads on first post. i tried with this functions:

add_action( ‘wp_head’, ‘adsense_auto_ads’ );
function adsense_auto_ads() {

if ( ($wp_query->current_post +1) != ($wp_query->post_count) ) {
return;
}

?>
<script async src=”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: “ca-pub-xxx”,
enable_page_level_ads: true
});
</script>
<?php
}

When i put:

if ( ($wp_query->current_post +1) != ($wp_query->post_count) ) {
echo ‘text’;
}

is working, but the adsense code is not removed. 🙂

Read more here:: exclude last wordpress blogpost

Leave a Reply

Your email address will not be published. Required fields are marked *