Disable WordAds on Specific WordPress Pages

If you want to programmatically disable WordAds on 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 four 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 pages. For example, if you were wanting ads more-or-less everywhere except within the WooCommerce parts of your Web site, use something like 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.

    Formerly, CEO and lead developer of a technology company, focusing on the merchant services space. Formerly, of WHMCompleteSolution (WHMCS).

    An avid gamer.

Leave a comment

lexical-absolute
lexical-absolute
lexical-absolute
lexical-absolute
%d bloggers like this: