Patreon WordPress - How to hide ads for patrons

How to hide ads for patrons of a certain level or above


By using the copy/paste code included below, you can hide ads from your patrons at a certain tier or above. You can use this code to hide ads in any section of your website. All you need to do is to copy/paste the code to relevant theme element and put the ad inside.

How to use the code:

1 - Just copy/paste the below code into your theme file where ads show.
2 - Make sure the code is not pasted inside other <?php ?> tags. 
3 - Replace 7 with the $ value that you want to gate the content with
4 - Paste your ad code in between the markers <!-- Post your ad code below → … <!-- Post your ad code above →. If the ad code already exists in the theme part which you are editing, move it to in between the markers.
5 - If you want to show something else to qualifying patrons instead of ads, replace it with “We have hidden the ads for you! Thank you for being our patron!” text in the last part. If you dont want to show anything, just delete the “We have hidden the ads for you! Thank you for being our patron!” text.
5- Done!

<?php

// Replace 7 with the $ value at or over which you want to hide ad. Any patron with this or higher pledge level will not see ads
$patreon_hide_ads_at_and_above = 7;
                
$patreon_show_hide_ad = <<<EOD

<!-- Post your ad code below -->

AD!

<!-- Post your ad code above -->

EOD;
// There should be no space before above line!

$patreon_ad_or_not = Patreon_Frontend::hide_ad_for_patrons( $patreon_hide_ads_at_and_above, $patreon_show_hide_ad );

if ( $patreon_ad_or_not != '' ) {
        echo $patreon_ad_or_not;
}
else {
?>
 <!-- If you have any content which you want to show to patrons who wont see ads, paste it below -->
 
We have hidden the ads for you! Thank you for being our patron!
 
 <!-- If you have any content which you want to show to patrons who wont see ads, paste it above -->

<?php                        
        
}
?>