Support Forum

Any thoughts for a advertisement plugin?

26 Answers

New Answer

KV kvr28
kvr28
Member

nice, this may sound like a weird question, is there any way to disable the ads if members are logged in?

YS Yellow Swordfish
Yellow Swordfish
Member

You can wrap your ad code like this…

if ( ! is_user_logged_in() ) {
    ... your ad code here...
}

This is a core WordPress function that returns true or false so this will only run the ad code if the user is NOT logged in.

KV kvr28
kvr28
Member

thanks yellow, I would still need the echo at the top and the comma semi-colon at the end though correct? 

KV kvr28
kvr28
Member

would it look like this?

echo ‘if ( ! is_user_logged_in() ) {<script async src=”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>
<!– Responsive –>
<ins class=”adsbygoogle”
style=”display:block”
data-ad-client=”xxxxxxxxxxxxx”
data-ad-slot=”xxxxxxxx”
data-ad-format=”auto”></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>’;}

MP Mr Papa
Mr Papa
Member

No….

if (!is_user_logged_in()) {
    echo '
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!– Responsive –>
    <ins class="adsbygoogle"
    style="display:block"
    data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
    data-ad-slot="xxxxxxxxx"
    data-ad-format="auto"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    ';
}
KV kvr28
kvr28
Member

lets try this again, if I wanted to show it on every say 3rd post, would I do this?

if

($spTopicView->currentPost==3){

if (!is_user_logged_in()) {
    echo '
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!Responsive –>
    <ins class="adsbygoogle"
    style="display:block"
    data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
    data-ad-slot="xxxxxxxxx"
    data-ad-format="auto"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    ';
}
}

MP Mr Papa
Mr Papa
Member

well, if you want it after every third post (what you asked for), that is not how one would do it.. but sounds like you have what you want?  It would show it only after the third post…