Disable ads under certain URLs

Posted in: Newspaper
Post count: 16

I want that every page/post under certain URL like http://example.com/nodads/ , the ads to be disabled or replaced with a different code.

I can write a simple plugin like:

if (preg_match('/noads\/i', $_SERVER['REQUEST_URI'], $match)) {
....
add_filter('wp_header_ad','replace_header_ad',50,1);
}

but I don’t know how to access theme’s ads code (wp_header_ad).

Any hints? Should I dig deeper in the documentation?

Thanks!

Post count: 16

Messy solution but does the job for a while:

function uniquename_callback($buffer) {
$buffer=str_replace('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>', '<!-- Ads removed -->', $buffer);
return $buffer;
}
function uniquename_buffer_start() { ob_start("uniquename_callback"); }
function uniquename_buffer_end() { ob_end_flush(); }

if (preg_match('/(noads|nocommercials)\//i', $_SERVER['REQUEST_URI'], $match)) {
add_action('after_setup_theme', 'uniquename_buffer_start');
add_action('shutdown', 'uniquename_buffer_end');
}

Replace “uniquename” with your own string to avoid accidental conflicts. Of course, caching is strongly recommended.

Post count: 16

Or this solution, if you want to edit theme’s own files, and include more filters, like “is_404()”: https://forum.tagdiv.com/topic/disable-ads-on-error-page-and-termsconditionprivacy-policy-in-newspaper-theme/

Viewing 3 posts - 1 through 3 (of 3 total)
The forum ‘Newspaper’ is closed to new topics and replies.