Disable ads if the user has an active subscription

Hi, I have recently started my blog with ghost and I have implemented adsense ads. I would like to know if there is a way to make the ads on my page disappear if the user is logged in and has an active subscription.

Thank you very much in advance.

In your theme, this snippet will only output if the current visitor is not a logged-in member

{{^if @member}}
  // ad code
{{/if}}
 

Sorry, I missed that you said “has an active subscription” - the snippet above is for any logged-in member, for paid members only, use:

{{^if @member.paid}}
  // ad code
{{/if}}
2 Likes

The problem is that I’m using the insert script feature so I don’t know how to put the script.

Do you mean code injection inside ghost admin? Yeah, it wouldn’t work there - you’d need to edit your theme to do this

What file I need to edit.

default.hbs

partials/post-card.hbs

Wow. So this mean it’s possible to create ads free blog if it’s paid. Something like pay to remove ads. Nice one @John . Was about to suggest this. But it’s there already.

1 Like

Thanks for this! I was trying to get this to work using code injection on the admin panel as I’m using a hosted theme (and I really need this to work). Is there any way to use this ({{^if @member.paid}}) in code injection or other places on a page/post without a custom/self-hosted theme?

Due to the maintenance and updates, I’m trying to avoid forking a theme at all costs. If this is not an option currently, can we suggest it?

This is amazing thanks @John

Is there a way to insert this into html cards?

It’s not possible to do this anywhere in admin — has to be in theme files

Thanks for confirming John.

Out of interest, as I’m not a developer in any way. If I attempt to update an official Ghost theme by adding some of these ad placements, then the ghost theme is updated. Will this overwrite any changes I’ve applied myself when I install/upgrade via Ghost themes?

Does this even work if the user is admin?

No, themes have no visibility of staff users (admins), only members.

A post was merged into an existing topic: How can I disable some scripts for admin users