1. Government Frontend Component Guide
  2. Machine readable metadata

Component

Machine readable metadata

Generates schema.org JSON-LD for use by search engines

This component doesn’t output anything visible. It generates “structured data” in JSON-LD format, with schema.org schemas.

Search for usage of this component on GitHub

How it looks (preview all)

<script type="application/ld+json">
  {"@context":"http://schema.org","@type":"Article","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.gov.uk/foo"},"headline":"A title","datePublished":null,"dateModified":null,"description":null,"publisher":{"@type":"Organization","name":"GOV.UK","url":"https://www.gov.uk","logo":{"@type":"ImageObject","url":"https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-logo-e5962881254c9adb48f94d2f627d3bb67f258a6cbccc969e80abb7bbe4622976.png"}},"image":["https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-1x1-5ceffac04f7f6d4f421bd1d36dbb723ef48c15426d7f77f90be80a83af3c747e.png","https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-4x3-fcfe16abb1a015848e50d2ea797666a9eaf5158dca38ddfb1e52dc8c0543ab74.png","https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-16x9-fcf616879a7b37970df4d2117de962e08f7d057674ef1af6063dcdd529424eee.png"]}
</script>

<link rel="canonical" href="https://www.gov.uk/foo" />

<meta property="og:site_name" content="GOV.UK" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.gov.uk/foo" />
<meta property="og:title" content="A title" />
<meta property="og:description" content="" />

  <meta name="twitter:card" content="summary" />

How to call this component

<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "A title",
    base_path: "/foo",
    details: {
    }
  },
  schema: "article"
} %>

Accessibility acceptance criteria

The HTML should not be visible.

Other examples

With description (preview)

<script type="application/ld+json">
  {"@context":"http://schema.org","@type":"Article","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.gov.uk/foo"},"headline":"A title","datePublished":null,"dateModified":null,"description":"Some manually set description of the page","publisher":{"@type":"Organization","name":"GOV.UK","url":"https://www.gov.uk","logo":{"@type":"ImageObject","url":"https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-logo-e5962881254c9adb48f94d2f627d3bb67f258a6cbccc969e80abb7bbe4622976.png"}},"image":["https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-1x1-5ceffac04f7f6d4f421bd1d36dbb723ef48c15426d7f77f90be80a83af3c747e.png","https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-4x3-fcfe16abb1a015848e50d2ea797666a9eaf5158dca38ddfb1e52dc8c0543ab74.png","https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-16x9-fcf616879a7b37970df4d2117de962e08f7d057674ef1af6063dcdd529424eee.png"]}
</script>

<link rel="canonical" href="https://www.gov.uk/foo" />

<meta property="og:site_name" content="GOV.UK" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.gov.uk/foo" />
<meta property="og:title" content="A title" />
<meta property="og:description" content="Some manually set description of the page" />

  <meta name="twitter:card" content="summary" />
<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "A title",
    base_path: "/foo",
    details: {
    }
  },
  schema: "article",
  description: "Some manually set description of the page"
} %>

With canonical url (preview)

<script type="application/ld+json">
  {"@context":"http://schema.org","@type":"Article","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.gov.uk/foreign-travel-advice/andorra/health"},"headline":"A title","datePublished":null,"dateModified":null,"description":null,"publisher":{"@type":"Organization","name":"GOV.UK","url":"https://www.gov.uk","logo":{"@type":"ImageObject","url":"https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-logo-e5962881254c9adb48f94d2f627d3bb67f258a6cbccc969e80abb7bbe4622976.png"}},"image":["https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-1x1-5ceffac04f7f6d4f421bd1d36dbb723ef48c15426d7f77f90be80a83af3c747e.png","https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-4x3-fcfe16abb1a015848e50d2ea797666a9eaf5158dca38ddfb1e52dc8c0543ab74.png","https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-16x9-fcf616879a7b37970df4d2117de962e08f7d057674ef1af6063dcdd529424eee.png"]}
</script>

<link rel="canonical" href="https://www.gov.uk/foreign-travel-advice/andorra/health" />

<meta property="og:site_name" content="GOV.UK" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.gov.uk/foreign-travel-advice/andorra/health" />
<meta property="og:title" content="A title" />
<meta property="og:description" content="" />

  <meta name="twitter:card" content="summary" />
<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "A title",
    base_path: "/foo",
    details: {
    }
  },
  schema: "article",
  canonical_url: "https://www.gov.uk/foreign-travel-advice/andorra/health"
} %>

With body (preview)

<script type="application/ld+json">
  {"@context":"http://schema.org","@type":"Article","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.gov.uk/foo"},"headline":"A title","datePublished":null,"dateModified":null,"description":null,"publisher":{"@type":"Organization","name":"GOV.UK","url":"https://www.gov.uk","logo":{"@type":"ImageObject","url":"https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-logo-e5962881254c9adb48f94d2f627d3bb67f258a6cbccc969e80abb7bbe4622976.png"}},"image":["https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-1x1-5ceffac04f7f6d4f421bd1d36dbb723ef48c15426d7f77f90be80a83af3c747e.png","https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-4x3-fcfe16abb1a015848e50d2ea797666a9eaf5158dca38ddfb1e52dc8c0543ab74.png","https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-16x9-fcf616879a7b37970df4d2117de962e08f7d057674ef1af6063dcdd529424eee.png"],"articleBody":"Some other body"}
</script>

<link rel="canonical" href="https://www.gov.uk/foo" />

<meta property="og:site_name" content="GOV.UK" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.gov.uk/foo" />
<meta property="og:title" content="A title" />
<meta property="og:description" content="" />

  <meta name="twitter:card" content="summary" />
<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "A title",
    base_path: "/foo",
    details: {
    }
  },
  schema: "article",
  body: "Some other body"
} %>

A guide (preview)

<script type="application/ld+json">
  {"@context":"http://schema.org","@type":"FAQPage","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.gov.uk/how-to-train-your-dragon"},"headline":"How to train your dragon","datePublished":null,"dateModified":null,"description":null,"publisher":{"@type":"Organization","name":"GOV.UK","url":"https://www.gov.uk","logo":{"@type":"ImageObject","url":"https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-logo-e5962881254c9adb48f94d2f627d3bb67f258a6cbccc969e80abb7bbe4622976.png"}},"image":["https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-1x1-5ceffac04f7f6d4f421bd1d36dbb723ef48c15426d7f77f90be80a83af3c747e.png","https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-4x3-fcfe16abb1a015848e50d2ea797666a9eaf5158dca38ddfb1e52dc8c0543ab74.png","https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-16x9-fcf616879a7b37970df4d2117de962e08f7d057674ef1af6063dcdd529424eee.png"],"mainEntity":[{"@type":"Question","name":"How to train your dragon","url":"https://www.gov.uk/how-to-train-your-dragon","acceptedAnswer":{"@type":"Answer","url":"https://www.gov.uk/how-to-train-your-dragon","text":"\u003cp\u003eTraining scaly beasts can be tricky\u003c/p\u003e "}},{"@type":"Question","name":"Preparation","url":"https://www.gov.uk/how-to-train-your-dragon#preparation","acceptedAnswer":{"@type":"Answer","url":"https://www.gov.uk/how-to-train-your-dragon#preparation","text":" \u003cp\u003ePrepare by meditating and writing a will\u003c/p\u003e "}},{"@type":"Question","name":"Afterwards ","url":"https://www.gov.uk/how-to-train-your-dragon#afterwards","acceptedAnswer":{"@type":"Answer","url":"https://www.gov.uk/how-to-train-your-dragon#afterwards","text":"\u003cp\u003eYour next of kin may need a strong stomach\u003c/p\u003e\n"}}]}
</script>

<link rel="canonical" href="https://www.gov.uk/how-to-train-your-dragon" />

<meta property="og:site_name" content="GOV.UK" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.gov.uk/how-to-train-your-dragon" />
<meta property="og:title" content="How to train your dragon" />
<meta property="og:description" content="" />

  <meta name="twitter:card" content="summary" />
<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "How to train your dragon",
    base_path: "/how-to-train-your-dragon",
    details: {
      parts: [
        {
          slug: "overview",
          body: "A thing on how to train scaly beasts",
          title: "Overview"
        },
        {
          slug: "treating-injuries",
          body: "Get to know a good blacksmith",
          title: "Treating injuries"
        }
      ]
    }
  },
  body: sanitize("<p>Training scaly beasts can be tricky</p> <h2 id='preparation'>Preparation</h2> <p>Prepare by meditating and writing a will</p> <h2 id='afterwards'>Afterwards<h2> <p>Your next of kin may need a strong stomach</p>
    "),
  schema: "faq",
  canonical_url: "https://www.gov.uk/how-to-train-your-dragon"
} %>

Person schema (preview)

<script type="application/ld+json">
  {"@context":"http://schema.org","@type":"Person","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.gov.uk/foo"},"name":"A. Person","description":null}
</script>

<link rel="canonical" href="https://www.gov.uk/foo" />

<meta property="og:site_name" content="GOV.UK" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.gov.uk/foo" />
<meta property="og:title" content="A. Person" />
<meta property="og:description" content="" />

  <meta name="twitter:card" content="summary" />
<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "A. Person",
    base_path: "/foo",
    details: {
    }
  },
  schema: "person"
} %>

Organisation schema (preview)

<script type="application/ld+json">
  {"@context":"http://schema.org","@type":"GovernmentOrganization","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.gov.uk/foo"},"name":"Ministry of Organisation","description":null,"potentialAction":{"@type":"SearchAction","description":"Find all content from Ministry of Organisation","target":"https://www.gov.uk/search/all?keywords={query}\u0026order=relevance\u0026organisations%5B%5D=foo","query":"required"}}
</script>

<link rel="canonical" href="https://www.gov.uk/foo" />

<meta property="og:site_name" content="GOV.UK" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.gov.uk/foo" />
<meta property="og:title" content="Ministry of Organisation" />
<meta property="og:description" content="" />

  <meta name="twitter:card" content="summary" />
<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "Ministry of Organisation",
    base_path: "/foo",
    details: {
    }
  },
  schema: "organisation"
} %>

Organisation schema with related orgs (preview)

<script type="application/ld+json">
  {"@context":"http://schema.org","@type":"GovernmentOrganization","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.gov.uk/foo"},"name":"Magical Artefacts Agency","description":null,"parentOrganization":[{"@context":"http://schema.org","@type":"GovernmentOrganization","sameAs":"https://www.gov.uk/ministry-of-magic"}],"subOrganization":[{"@context":"http://schema.org","@type":"GovernmentOrganization","sameAs":"https://www.gov.uk/dodgy-wands-commission"}],"potentialAction":{"@type":"SearchAction","description":"Find all content from Magical Artefacts Agency","target":"https://www.gov.uk/search/all?keywords={query}\u0026order=relevance\u0026organisations%5B%5D=foo","query":"required"}}
</script>

<link rel="canonical" href="https://www.gov.uk/foo" />

<meta property="og:site_name" content="GOV.UK" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.gov.uk/foo" />
<meta property="og:title" content="Magical Artefacts Agency" />
<meta property="og:description" content="" />

  <meta name="twitter:card" content="summary" />
<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "Magical Artefacts Agency",
    base_path: "/foo",
    details: {
    },
    links: {
      ordered_parent_organisations: [
        {
          title: "Ministry of Magic",
          base_path: "/ministry-of-magic"
        }
      ],
      ordered_child_organisations: [
        {
          title: "Dodgy Wands Commission",
          base_path: "/dodgy-wands-commission"
        }
      ]
    }
  },
  schema: "organisation"
} %>

Organisation schema with people (preview)

<script type="application/ld+json">
  {"@context":"http://schema.org","@type":"GovernmentOrganization","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.gov.uk/foo"},"name":"Ministry of Organisation","description":null,"member":[{"@type":"Person","honorificPrefix":"Minister","image":"https://images.gov.uk/rufus.jpg","name":"Rufus Scrimgeour MP","url":"https://www.gov.uk/rufus-scrimgeour","hasOccupation":[{"@type":"Role","name":"Minister for Magic","url":"https://www.gov.uk/minister-for-magic"},{"@type":"Role","name":"Head of Auror Office","url":"https://www.gov.uk/head-of-auror-office"}]}],"potentialAction":{"@type":"SearchAction","description":"Find all content from Ministry of Organisation","target":"https://www.gov.uk/search/all?keywords={query}\u0026order=relevance\u0026organisations%5B%5D=foo","query":"required"}}
</script>

<link rel="canonical" href="https://www.gov.uk/foo" />

<meta property="og:site_name" content="GOV.UK" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.gov.uk/foo" />
<meta property="og:title" content="Ministry of Organisation" />
<meta property="og:description" content="" />

  <meta name="twitter:card" content="summary" />
<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "Ministry of Organisation",
    base_path: "/foo",
    details: {
      ordered_ministers: [
        {
          name_prefix: "Minister",
          name: "Rufus Scrimgeour MP",
          role: "Minister for Magic",
          href: "/rufus-scrimgeour",
          role_href: "/minister-for-magic",
          image: {
            url: "https://images.gov.uk/rufus.jpg"
          }
        },
        {
          name_prefix: "Minister",
          name: "Rufus Scrimgeour MP",
          role: "Head of Auror Office",
          href: "/rufus-scrimgeour",
          role_href: "/head-of-auror-office",
          image: {
            url: "https://images.gov.uk/rufus.jpg"
          }
        }
      ]
    }
  },
  schema: "organisation"
} %>

Search results page schema (preview)

<script type="application/ld+json">
  {"@context":"http://schema.org","@type":"SearchResultsPage","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.gov.uk/finder/all"},"headline":"The finding of all things","datePublished":null,"dateModified":null,"description":null,"publisher":{"@type":"Organization","name":"GOV.UK","url":"https://www.gov.uk","logo":{"@type":"ImageObject","url":"https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-logo-e5962881254c9adb48f94d2f627d3bb67f258a6cbccc969e80abb7bbe4622976.png"}},"image":["https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-1x1-5ceffac04f7f6d4f421bd1d36dbb723ef48c15426d7f77f90be80a83af3c747e.png","https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-4x3-fcfe16abb1a015848e50d2ea797666a9eaf5158dca38ddfb1e52dc8c0543ab74.png","https://government-frontend.herokuapp.com/government-frontend/govuk_publishing_components/govuk-schema-placeholder-16x9-fcf616879a7b37970df4d2117de962e08f7d057674ef1af6063dcdd529424eee.png"]}
</script>

<link rel="canonical" href="https://www.gov.uk/finder/all" />

<meta property="og:site_name" content="GOV.UK" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://www.gov.uk/finder/all" />
<meta property="og:title" content="The finding of all things" />
<meta property="og:description" content="" />

  <meta name="twitter:card" content="summary" />
<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "The finding of all things",
    base_path: "/finder/all",
    details: {
    }
  },
  schema: "search_results_page"
} %>