Usage

useContentHead() is available everywhere in your app where useHead would be.

It takes two arguments:

  • document: A document data (of any type)
  • to: A route path
    • Default: useRoute()
<script setup lang="ts">
const { data: page } = await useAsyncData('my-page', queryContent('/').findOne)

useContentHead(page)
</script>

Automation

When using the <ContentDoc /> component or the default document-driven page, the composable will be automatically used.

To disable the automation, you can set the contentHead option to false in your nuxt.config:

export default defineNuxtConfig({
  content: {
    contentHead: false
  }
})

Parameters

These parameters can be used from the Front-Matter section of your pages.

KeyTypeDefaultDescription
headobjectA useHead compatible object
titlestringWill be used as the default value for head.title
head.titlestringParsed titleSets the <title> tag
descriptionstringWill be used as the default value for head.description
head.descriptionstringParsed descriptionSets the <meta name="description"> tag
imagestring | objectWill be used as the default value for head.image
image.srcstringThe source of the image
image.altstringThe alt description of the image
image.xxxstringAny og:image:xxx compatible attribute
head.imagestring | objectOverrides the <meta property="og:image">

At the exception of title, description and image, the head object behaves exactly the same in Front-Matter as it would in useHead({ ... }) composable.

You can specify any value that is writeable in yaml format.

---
title: 'My Page Title'
description: 'What a lovely page.'
image:
  src: '/assets/image.jpg'
  alt: 'An image showcasing My Page.'
  width: 400
  height: 300
head:
  meta:
    - name: 'keywords'
      content: 'nuxt, vue, content'
    - name: 'robots'
      content: 'index, follow'
    - name: 'author'
      content: 'NuxtLabs'
    - name: 'copyright'
      content: '© 2022 NuxtLabs'
---

Surround

[
  {
    "title": "fetchContentNavigation()",
    "path": "/content-v2/composables/fetch-content-navigation",
    "stem": "content-v2/3.composables/2.fetch-content-navigation",
    "description": "The fetchContentNavigation utility returns a tree of items based on the content/ directory structure and files."
  },
  {
    "title": "useContentHelpers()",
    "path": "/content-v2/composables/use-content-helpers",
    "stem": "content-v2/3.composables/4.use-content-helpers",
    "description": "Helpers to interact with the navigation object."
  }
]