Block ADs For Buyers

Hi! I am currently using the HTML feature in my blog post, and I have a snippet in my entire sites header for ADs, most ADs are banners which I manually put in spots on the blog post, then the one in the header is the code that redircts to a different page if they click a few times, but I can’t seem to check if they have any of my paid subscriptions or not, if they have a paid subscription I want to not show the AD, but if they do not, or are not logged in I want it to show the ADs:

Banner code in posts:

<script type="text/javascript">
	atOptions = {
		'key' : '',
		'format' : 'iframe',
		'height' : 90,
		'width' : 728,
		'params' : {}
<script type="text/javascript" src="//"></script>

I would also like to somehow make it where if someone has Adblock it requires them to sign in to the website, it does not require them to turn it off

Can’t help you with the adblock detection, but if you can edit the theme, you’d want to do something like this. (Note: .hbs and .js hybrid coming up! Will NOT work in code injection

{{#if @member.paid}}
{{!-- member is paid, do nothing here --}}
<script type="text/javascript" src="//"></script>

That’ll selectively add the ads js code. Alternatively, you can set a .js variable, then later check if it is set.

If you only have access to code injection, I’d use javascript to look at the theme’s “subscribe / log out” button that appears at the top of the menu bar in many themes. Detect the difference there, and use that to decide if the visitor is signed in. (You could possibly also make a call to the /members endpoint, or if you just need to know if they’re logged in, check for the appropriate Ghost cookie.)

Edit: added a missing /if.

1 Like


I have a new update, so instead of doing all that, on the post where I need them set I put the below, but it seems it cannot find the checkIfEnabled() specified on the other script below:

Script in my post editor (HTML)

    // Check if enabled, then conditionally load the script
    if (checkIfEnabled()) {
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = '//';

Script in post.hbs (Theme file in dawn theme, check var checkIfEnabled = true)

<main class="site-main">
        {{> "content" width="wide"}}
        {{#unless @member.paid}}
                var checkIfEnabled = true; // Define checkIfEnabled variable
            <script type='text/javascript' src='//'></script>  // This is another AD script, which currently works with this method.

    {{#if @custom.show_related_posts}}
        {{> "related-posts"}}

        {{> "comments"}}

Checkifenabled() is trying to call a function, not get the value of a variable.