Prevent Nuxt from escaping the meta title
Does anyone know if it's possible to prevent Nuxt from escaping test when writing the title?
I'm trying to add a slash, eg:
testing w/ a slash
and it escapes it to: <title>testing w/ a slash</title>
3 Replies
Hi @hiimmox. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To prevent Nuxt from escaping characters in the meta title, you can use the
useHead
composable with the innerHTML
property. This allows you to set raw HTML content for the title, which won't be automatically escaped by Nuxt.
Here's an example of how you can do this:
By using the innerHTML
property, you can include special characters like slashes without them being escaped.
However, it's important to note that this approach bypasses the built-in security measures that protect against potential XSS attacks. Only use this method if you're certain that the title content is safe and doesn't contain any user-generated or untrusted input.
For more information on using useHead
and managing meta tags in Nuxt, you can refer to the SEO and Meta documentation.
Docs > Api > Composables > useHead provides more details on the useHead
composable and its usage.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@327193365797928963> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
innerHtml only works for script tags
I ended up creating a nitro hook: