Offer members an ad-free experience

In this article, we’ll show you how to provide your members with an ad-free experience on your WordPress site. This approach provides your paid subscribers with an interruption-free browsing experience, while allowing you to maintain ad revenue for visitors.

In this help doc:

Hide ads using WP functions

One way to hide ads for paying members is to leverage Memberful’s WordPress functions to add an HTML/CSS class to the page which would determine whether the ads should be displayed or not.

First, we'll use our WP function is_subscribed_to_any_memberful_plan() to determine whether or not a user is a paying member.

If they are, use the body_class filter to add a custom class to the page's tag. The following snippet can be added to your theme's functions, either by inserting it into the functions.php file or by using a code snippets plugin with the capability to add new WordPress functions.

function add_memberful_body_class( $classes ) {
    if ( is_subscribed_to_any_memberful_plan( wp_get_current_user()->ID ) ) {
        $classes[] = 'active-memberful-member';
    }
    return $classes;
}
add_filter( 'body_class', 'add_memberful_body_class' );

In the above example, the active-memberful-member class is added to the page's tag whenever the current user is subscribed to any plan.

You can then use CSS to hide any ads if that class is present.

body.active-memberful-member .ad {
    display: none;
}

Alternatively, you could use JavaScript to hide ads when the class is present:

document.addEventListener('DOMContentLoaded', function() {
    if (document.body.classList.contains('active-memberful-member')) {
        const ads = document.querySelectorAll('.ad');
        ads.forEach(function(ad) {
            ad.style.display = 'none';
        });
    }
});

The examples above hide any elements that have the ad class, but you can adjust the selector to match your specific ad implementation.

This approach works well with Mediavine, a full-service ad management platform. Once the body tag is in place, contact Mediavine support and ask them to hide ads when this class is present.

It also works well with Raptive (formally Ad Thrive), a popular ad network focused on helping creators make money through ads.

Hide ads using subscriber roles

If your ads platform supports hiding ads for paying members based on their user roles in WordPress, you could use this functionality in conjunction with Memberful’s Advanced Role Mapping.

This approach works well with Advanced Ads, a popular WordPress plugin for managing ads on your site. Review their documentation to learn how to disable ads for certain user roles.

Related help docs:

Can't find what you're looking for? We'd love to help! 💪

Send us a message and you'll hear back within a few hours Monday - Friday. 😀