1. 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.

How to call this component

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

How it looks

<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://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-logo-e5962881254c9adb48f94d2f627d3bb67f258a6cbccc969e80abb7bbe4622976.png"}},"image":["https://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-schema-placeholder-1x1-5ceffac04f7f6d4f421bd1d36dbb723ef48c15426d7f77f90be80a83af3c747e.png","https://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-schema-placeholder-4x3-fcfe16abb1a015848e50d2ea797666a9eaf5158dca38ddfb1e52dc8c0543ab74.png","https://govuk-publishing-components.herokuapp.com/assets/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" />

Accessibility acceptance criteria

The HTML should not be visible.

Other examples (preview all)

With description (preview)

<%= 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"
} %>
<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://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-logo-e5962881254c9adb48f94d2f627d3bb67f258a6cbccc969e80abb7bbe4622976.png"}},"image":["https://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-schema-placeholder-1x1-5ceffac04f7f6d4f421bd1d36dbb723ef48c15426d7f77f90be80a83af3c747e.png","https://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-schema-placeholder-4x3-fcfe16abb1a015848e50d2ea797666a9eaf5158dca38ddfb1e52dc8c0543ab74.png","https://govuk-publishing-components.herokuapp.com/assets/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" />

With canonical url (preview)

<%= 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"
} %>
<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://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-logo-e5962881254c9adb48f94d2f627d3bb67f258a6cbccc969e80abb7bbe4622976.png"}},"image":["https://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-schema-placeholder-1x1-5ceffac04f7f6d4f421bd1d36dbb723ef48c15426d7f77f90be80a83af3c747e.png","https://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-schema-placeholder-4x3-fcfe16abb1a015848e50d2ea797666a9eaf5158dca38ddfb1e52dc8c0543ab74.png","https://govuk-publishing-components.herokuapp.com/assets/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" />

With body (preview)

<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "A title",
    base_path: "/foo",
    details: {
    }
  },
  schema: "article",
  body: "Some other body"
} %>
<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://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-logo-e5962881254c9adb48f94d2f627d3bb67f258a6cbccc969e80abb7bbe4622976.png"}},"image":["https://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-schema-placeholder-1x1-5ceffac04f7f6d4f421bd1d36dbb723ef48c15426d7f77f90be80a83af3c747e.png","https://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-schema-placeholder-4x3-fcfe16abb1a015848e50d2ea797666a9eaf5158dca38ddfb1e52dc8c0543ab74.png","https://govuk-publishing-components.herokuapp.com/assets/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" />

Person schema (preview)

<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "A. Person",
    base_path: "/foo",
    details: {
    }
  },
  schema: "person"
} %>
<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" />

Organisation schema (preview)

<%= render "govuk_publishing_components/components/machine_readable_metadata", {
  content_item: {
    title: "Ministry of Organisation",
    base_path: "/foo",
    details: {
    }
  },
  schema: "organisation"
} %>
<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" />

Organisation schema with related orgs (preview)

<%= 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"
} %>
<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" />

Organisation schema with people (preview)

<%= 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"
} %>
<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" />

Search results page schema (preview)

<%= 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"
} %>
<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://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-logo-e5962881254c9adb48f94d2f627d3bb67f258a6cbccc969e80abb7bbe4622976.png"}},"image":["https://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-schema-placeholder-1x1-5ceffac04f7f6d4f421bd1d36dbb723ef48c15426d7f77f90be80a83af3c747e.png","https://govuk-publishing-components.herokuapp.com/assets/govuk_publishing_components/govuk-schema-placeholder-4x3-fcfe16abb1a015848e50d2ea797666a9eaf5158dca38ddfb1e52dc8c0543ab74.png","https://govuk-publishing-components.herokuapp.com/assets/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" />