How to replace the Article schema with NewsArticle in {{ghost_head}} (using PikaPods + Headline theme)?

Hi everyone,

I’m customizing the Headline theme and I want to replace the default JSON-LD schema @type: "Article" injected via {{ghost_head}} with @type: "NewsArticle".

I’ve already created a newsarticleschema.hbs file with the correct NewsArticle markup, and it works when inserted manually. However, when I include {{ghost_head}} in the <head>, it automatically adds the default Article schema, resulting in two conflicting schemas (Article and NewsArticle) on each post.

If I remove {{ghost_head}}, I lose important functionality such as:

  • Google AdSense
  • Social share buttons with embedded CSS
  • Code injection set in the Admin panel (header section)

Environment:

  • Ghost version: latest
  • Hosting: PikaPods
  • Theme: Headline

Question:

Is there a native or recommended way to override or replace the Article schema with NewsArticle in Ghost without removing {{ghost_head}}?

If not, is there any flag, helper, or clean workaround to handle this properly at the theme level?

Thanks in advance.

Yes! I did something about this last year:

You will need to edit the theme. So what you’re going to do is find where default.hbs currently calls {{ghost_head}}. Wrap that in some logic.

So perhaps, if you want to write custom schema only for posts or pages that have the tag #use-alt-schema:
(caution, made up on the spot, could have an error)

{{#is "post, page"}}
{{#post}}
  {{#has tag="#use-alt-schema"}}
      {{> newsarticleschema }}  {{!-- assumes this file is in partials --}}
      {{ghost_head exclude="schema"}}
  {{else}}
      {{ghost_head}}
  {{/has}}
{{/post}}
{{else}}
   {{ghost_head}}
{{/is}}

You’ll need to make sure you’re writing out a full set of schema for the pages that you’re excluding it from ghost_head. Be sure to include author, organization, etc.

1 Like