Is it possible to have a type of ad show for certain pages only?

Joined
May 10, 2015
Messages
236
Likes
134
Degree
1
As per above.

I'm planning to buy FB traffic to my site. I have pops on my site to monetize, and the ads are doing well. But FB doesn't allow pops. So I want to make it so that the page I send FB traffic to won't have pops, but if they click through to any other article the pops will show.

How hard is it to do this?
 
If you know any code yourself it should be pretty easy to do.

Just throw a variable into the query string of FB traffic. The ad code that triggers the pop would need to be set up so it only triggers if that variable is not there.

So you can write a simple JS function that reads the URL and if it sees "nopop" anywhere in it. It does nothing. If it doesn't it goes ahead and redirects to your ad network pop script.

If you hate coding you can use Google Tag Manger to do this. Your ad code for a pop up is the same thing as a "tag" at the end of the day and they have the features build in already to only fire Tags if certain criteria is met. But it's definitely overkill for what you need though.
 
Mike's method is the right way to do it, but I did have something else pop in my head that I might as well mention.

This completely hinges on how the code for the pop ups is implemented but I'm guessing it's a <script>. Depending on what CMS you're using and other variables, you could write a PHP if-loop around that script so that the logic says... "If it's NOT this particular page, show the pop up".

Later, it'd be a 10 second ordeal to remove that loop if you decide to stop driving FB traffic to the page.
 
Miket's way is more dynamic for sure, but sadly I don't have the skills to pull it off. Yes the code is just a simple one line <script> thing.

I tried some php in the functions.php but it's not working. I have the script in the header so it loads on all the pages by default. So now I'm trying to write another piece of code to disable the ads on the page receiving traffic.

So a solution I found was this:
if( !is_page('x')) { ?>
// ad script
<?php }

where x is the post id.
 
Last edited:
This is the code I put in the header but it doesn't seem to be working:

<? php $no_pop=get_post(790);
if(!$no_pop){ ?>
<!-- ad code-->
<?php } ?>

But it's not working.. what am I doing wrong here?
 
<? php $no_pop=get_post(790);
if(!$no_pop){ ?>
<!-- ad code-->
<?php } ?>

I believe it should be:
Code:
<?php
$no_pop=get_post(790);
if(!$no_pop){
echo "<!-- ad code-->";
}
?>

But don't quote me on that, cause I only code/edit php when it's other people's code.
 
^ @Krass That should do it. If you want, you can avoid the variable $no_pop altogether.
 
I believe it should be:
Code:
<?php
$no_pop=get_post(790);
if(!$no_pop){
echo "<!-- ad code-->";
}
?>

But don't quote me on that, cause I only code/edit php when it's other people's code.

Thanks for that, looks much better. Btw the reason I closed the php is because the ad code is in javascript. So here's what it looks like now:

<?php
if(!get_post(790)){
echo 'javascript code';
echo 'javascript code';
}
?>
So no errors, but it's still not working.. what did I mess up this time? The javascript uses " so I used ' to close the echo.
 
You may need to look at htmlspecialchars_decode() and htmlspecialchars(), but without seeing what you've written, it is hard to say. Why don't you post the actual code? Someone here then can tell you why it's not working, rather than going through it like this in bits and pieces.
 
You may need to look at htmlspecialchars_decode() and htmlspecialchars(), but without seeing what you've written, it is hard to say. Why don't you post the actual code? Someone here then can tell you why it's not working, rather than going through it like this in bits and pieces.

Not sure why I didn't post the whole thing. Here's the whole code:

//Propellerads Code
<?php
$no_pop=get_post(790);
if(!$no_pop){
echo '<script src="//go.mobtrks.com/notice.php?p=519893&interstitial=1"></script>';
echo '<script type="text/javascript" src="//go.oclaserver.com/apu.php?zoneid=557965"></script>';
}
?>
//End Propellerads code
 
Go to the page the code is suppose to be on and view the source code and see if it is there. If you are tracking mobile use a browser plugin to switch your user-agent to iphone or some smartphone and then load the page and view the source code. If it is there then the logic works. If not then the if statement is not null.
 
I think your problem is get_post();

Try....

Code:
<?php if(!is_single('790')) {
echo 'javascript code';
} ?>

The is_ series of functions are conditionals with boolean results (true/false), whereas the get_ functions are actually fetching data related to the post.

See this for more uses with slugs, ID's, titles, arrays of posts, etc: http://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page

If you're using Pages and not Posts, then it's just a swap to is_page() instead of is_single()
 
I think your problem is get_post();

Try....

Code:
<?php if(!is_single('790')) {
echo 'javascript code';
} ?>

The is_ series of functions are conditionals with boolean results (true/false), whereas the get_ functions are actually fetching data related to the post.

See this for more uses with slugs, ID's, titles, arrays of posts, etc: http://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page

If you're using Pages and not Posts, then it's just a swap to is_page() instead of is_single()

Yup, that did it! The code works now. So the ads only trigger once they are out of that post. So now I'm testing whether FB doesn't like pops for the whole domain or just the destination page from the ad. Thanks, Ryu!
 
Back