- This topic has 5 replies, 2 voices, and was last updated 5 years, 8 months ago by Tom.
-
AuthorPosts
-
August 14, 2018 at 6:01 pm #648505Alessio
Good morning,
we are trying to NOT display adsense on some posts and pages, because of the google adsense policy.
I found a script, which works fine when we try to exclude only one post, but it creates problems when we add a comma and more post id’sthe problems we find are: now the categories pages are empty (no content) and the wordpress toolbar does not appear when we browse our sites while logged in. if we exclude just one post, it all works fine, if we add more than one (see below) the problem comes back
we added the following script to the footer hook
<?php
$currentpageid = get_the_ID();
If ($currentpageid != 64,7440,2443) {
echo “<script async src=\”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\”></script>”;
}
?>all our adsense tags are without the pagead2.googlesyndication.com/pagead/js/adsbygoogle.js script, so the tags should not work only on posta and pages where they cannot be displayed
please if you can, we would appreciate your help in understanding where the problem is
thank you in advance
alexAugust 14, 2018 at 7:23 pm #648585TomLead DeveloperLead DeveloperHi there,
Try this:
$exclude = array( 64, 7440, 2443 ); if ( ! is_page( $exclude ) ) { // Stuff in here is excluded. }
August 14, 2018 at 11:26 pm #648718Alessiohi tom,
thank you first of all.I tried to replace my (working when using only one page number) script with the one you gave me, but it gives exactly the same problem I am having with the original script – in the case of the new code the problem happens even when using just one post number (wordpress toolbar not diplayed and categories pages empty)
I apologize if maybe I was not able to understand your suggestion, this is how I tried to implement it
I added to the wp_footer hook the following
<?php
$exclude = array( 62, 7640, 2143 );
if ( ! is_page( $exclude ) ) {
// Stuff in here is excluded.
<script async src=”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>
}
?>And enabled Execute PHP
But it does not work.
If you have any other advice on how to exclude adsense only from specific posts and pages, I will be glad to hear. In the meantime I will try to find alternative options, and if I find a solution I will write it on this page
Thank you again, your theme is amazing and support from your team is really top
Best regards
AlexAugust 15, 2018 at 9:49 am #649475TomLead DeveloperLead DeveloperTry using this code instead:
<?php $exclude = array( 62, 7640, 2143 ); if ( ! is_page( $exclude ) ) { ?> // Stuff in here is excluded. <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <?php } ?>
Alternatively you can use our new Elements module: https://docs.generatepress.com/article/hooks-element-overview/
It has Display Rules so you can ditch the PHP completely.
August 15, 2018 at 6:41 pm #650008AlessioHi Tom
The new Elements is definitely powerful, and within one minute the problem was fixed. No need for PHP, just use elements.
Thank you for your support and for the GREAT theme, really appreciated
Alex
August 15, 2018 at 7:14 pm #650023TomLead DeveloperLead DeveloperThat’s great to hear! Thank you 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.