You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: How to display og images for error pages
4
+
---
5
+
6
+
Nuxt OG Image supports displaying images for pages with a non-200 status code (for example a 404 page). It supports both errors thrown by Nuxt, as well as custom errors created using `setResponseStatus`.
7
+
8
+
To define an og image for an error page, call `defineOgImageComponent` in the setup script of your `error.vue` file:
9
+
10
+
```vue [error.vue]
11
+
<script lang="ts" setup>
12
+
defineOgImageComponent('NuxtSeo')
13
+
</script>
14
+
```
15
+
16
+
You can use this, for example, to display a generic OG Image containing the status code and status message by
17
+
accessing the error provided by Nuxt:
18
+
19
+
```vue [error.vue]
20
+
<script lang="ts" setup>
21
+
import type { NuxtError } from '#app'
22
+
23
+
const props = defineProps<{
24
+
error: NuxtError
25
+
}>()
26
+
27
+
defineOgImageComponent('NuxtSeo', {
28
+
title: error.statusCode.toString(),
29
+
description: error.statusText
30
+
})
31
+
</script>
32
+
```
33
+
34
+
## Limitations
35
+
36
+
Note that displaying OG Images for error pages is only supported for status codes ranging 400 to 499. Pages with status codes >= 500 won't generate an OG Image.
statusMessage: `[Nuxt OG Image] HTML response from ${path} is missing the #nuxt-og-image-options script tag. Check you have used defined an og image for this page.`,
293
+
statusMessage: `[Nuxt OG Image] HTML response from ${path} is missing the #nuxt-og-image-options script tag. Make sure you have defined an og image for this page.`,
0 commit comments