Disable WordAds on Specific WordPress Pages

WordAds

If you want to programmatically disable WordAds on particular pages within WordPress, you can do so with the code below.

function disable_wordads() {
    add_filter('wordads_content_disable', '__return_true');
    add_filter('wordads_excerpt_disable', '__return_true');
    add_filter('wordads_header_disable', '__return_true');
    add_filter('wordads_inpost_disable', '__return_true');
}

add_action('template_redirect', 'disable_wordads');

There are 4 different filters in the above function. Use a combination of one or all of them as needed.

Use conditionals to only disable specific types of WordAds on particular pages. For example, if you were wanting ads more-or-less everywhere except within the WooCommerce parts of your Web site, use something similar to the code below.

function disable_wordads() {
    if (
        is_account_page() || is_cart() || is_checkout() || is_product() || is_product_category() || is_product_tag() || is_shop() || is_wc_endpoint_url() || is_woocommerce()
    ) {
        add_filter('wordads_content_disable', '__return_true');
        add_filter('wordads_excerpt_disable', '__return_true');
        add_filter('wordads_header_disable', '__return_true');
        add_filter('wordads_inpost_disable', '__return_true');
    }
}

add_action('template_redirect', 'disable_wordads');

Author

  • I tried to fix the world, but God wouldn't give me his source code. For several years, I was CEO of and lead developer at a technology company, focusing on the merchant services space. I've been directly contracted by companies, including but not limited to, cPanel and WHMCompleteSolution (WHMCS). An avid gamer.