Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Make ads not show up on 10 wordpress posts WordPress

I run adsense on a site. I need ads to not show up on 10 different posts because they have material google says is a violation in them. I have 4 ads on the site. one in the header, two in the post and one in a sidebar. All ads must not run when those posts show up.

Answers (6)

2011-11-22

Luis Cordova answers:


<?php

is_single( array( 17, 19, 1, 11 ) ) {
// don't show anything
} else {
// here goes your previous code the one you have already
// on your site call to function for ad plugin
}


Luis Cordova comments:

so basically in every part that an add is shown you have to wrap the call to the ads function or shortcode with that if else statement as shown above.


Luis Cordova comments:

I will do this for you pleaes send me the information login access via Private Message by clicking on my name


Luis Cordova comments:

the other way is to


if( !get_post_meta( $post->ID, 'no_ads', true ) == "yes" ) {

// actual ads code

}


as Julio said, however the instruction that was missing was that you have to go to the backend and edit and set under the box for custom fields and set one with label "no_ads" and set that to "yes" as value for when the case you don't want ads to show on those posts.


ravetildon comments:

The blog has 2000+ posts. How can all posts be set to display ads and then I manually just add code to the 10?


Luis Cordova comments:

that is easy, the template insert is valid for all, so it is not manual work

the only manual work is from the dashboard on editing a single value on 10 posts

provide me access and i will do it right away


ravetildon comments:

I cant seem to get code to work, gives me whie screen. Do I have way to contact you? Are we allowed instant messenger on here?


Luis Cordova comments:

yes it is allowed, just click my name or add me on skype cordova_luis
or gmail chat cordoval at gmail


Luis Cordova comments:

turned down working on this site for personal decision


ravetildon comments:

If I do this I get white screen. Am I missing an else statement or something?
<?php
if( !get_post_meta( $post->ID, 'no_ads', true ) == "yes" ) {
actual ads code
}
?>

2011-11-22

Julio Potier answers:

Hello

You can use custom post field, example :

You create a custom field named "no_ads" with value "yes".

In your theme, in every needed file, find the ads code and wrote a condition like this :

if( !get_post_meta( $post->ID, 'no_ads', true ) == "yes" ) {
// actual ads code
}


With this solution you don't need to modify each time your files when you want to add a post/page without ads.

I can do this for you, but i need FTP and/or admin account, this will be faster and easier.

See you soon !


ravetildon comments:

I cant get that code to work. gives me white screen. Do I have to enclose it in php start end tags or something?


ravetildon comments:

have gchat/skype, etc?


ravetildon comments:

If I do this I get white screen. Am I missing an else statement or something?
<?php
if( !get_post_meta( $post->ID, 'no_ads', true ) == "yes" ) {
actual ads code
}
?>


Julio Potier comments:

skype : julio.boiteaweb


ravetildon comments:

CAn I make certain tags not show the advertisement also?

2011-11-22

Romel Apuya answers:

try :
array is the id of each post that you contains harmfull content



<?php if( !is_single(array( 1, 2, 3, 4 ) ) ) : ?>
--- your ad code goes here -
<?php endif; ?>


ravetildon comments:

How do I keep a tag from displaying the add also?

2011-11-22

ej_emman answers:

Hello ravetildon,

Everyones suggestion is right, I also have another alternative that you can use. Just add category to the selected post you dont want to display ads.

I assume you add "no_ads_cat" category on selected post. And the codes will be..


<?php if(in_category($post->ID, 'no_ads_cat')): else: ?>

// your google adsense script place here

<?php endif; ?>


hope this helps


ravetildon comments:

How do I keep a tag from displaying the add also?

2011-11-22

Francisco Javier Carazo Gil answers:

As ej_emman says, I also suggest that you can use tags instead of categories.

The conditional now is:

has_tag( 'no_ad' );


Francisco Javier Carazo Gil comments:

Ravetildon, if you decide to use post_meta is very useful use metabox in admin panel.

How? I tell you, in your functions.php:


//add meta box
add_meta_box('wp_no_ad', 'No ad', 'wp_no_ad', 'post', 'side', 'high');

//function with meta box
function wp_no_ad()
{
global $post;

echo '<input type="hidden" name="no-ad_noncename" id="noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';

$no_ad = get_post_meta($post->ID, '_no_ad', true);

echo '<input type="checkbox" name="_no_ad" value="No ad"/>';
}

// function to save
function wp_no_ad_save_meta($post_id, $post)
{
if(!isset($_POST['ad_noncename']))
return;

if ( !wp_verify_nonce($_POST['ad_noncename'], plugin_basename(__FILE__) ))
return $post->ID;

if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;

$no_ad['_no_ad'] = $_POST['_no_ad'];

if(get_post_meta($post->ID, $key, FALSE))
update_post_meta($post->ID, $key, $value);
else
add_post_meta($post->ID, $key, $value);

if(!$value)
delete_post_meta($post->ID, $key);
}


ravetildon comments:

How do I keep a tag from displaying the add also?


Francisco Javier Carazo Gil comments:

@ravetildon: you can use this decision:

* If you use "no_ad" tag, ads are not displayed
* In other case: tag are displayed

Using meta_box and post_meta is another good and pretty solution.

2011-11-24

Paul Gregory answers:

The aspect of this that no-one has correctly coded for is "All ads must not run when those posts show up."

I understand this to mean that if one of the Google-disallowed posts was from February and had the tag "kittens", then there are a number of archive pages that need to omit Google adverts in all locations - so the header, the sidebar and all the other posts on the page need to show something else if there is 1 or more dodgy post showing up.

This is fiddly to do, but not impossible. It requires however a fairly major reordering of the theme so that the loop is run through before everything else, checking for one of the 10 posts, and then a variable is set. All the other ad slots need to check that global variable to know whether to show Google or some other ad network that's not as picky.

I can code that but not for $10 and not without seeing the theme, and it is of course possible that I find the 10 pages objectionable myself.

The other solution is of course to remove the offending posts from the posts section. Not necessarily remove them from the site, you could move them to pages using a different template, or replace the previous permalinked locations with edited static pages.