Skip to content

Cannot override meta description with transformHead #4812

Closed
@Zezombye

Description

@Zezombye

Describe the bug

    transformHead(context) {
        let description = context.pageData?.frontmatter?.layout === "home" ? "Zezombye's Blog" : "Programming, self-improvement, and various stuff";
        return [
            ['meta', { name: 'description', content: description }],
        ]
    },

Although the <meta name="description"> tag is overridden, it doesn't take into account the description, putting instead the default description of "A VitePress site":

Image

This does work if I put og:description, but Discord picks up the description tag.

Image

Reproduction

It doesn't seem the build works properly at vitepress.new but by putting the transformHead hook and removing the default description field in the config, it should reproduce.

Expected behavior

The tag should be properly overridden

System Info

System:
    OS: Windows 10 10.0.17763
    CPU: (8) x64 AMD Ryzen 5 1500X Quad-Core Processor
    Memory: 12.95 GB / 31.95 GB
  Binaries:
    Node: 22.14.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 10.7.0 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Chrome: 138.0.7204.49
    Internet Explorer: 11.0.17763.2989
  npmPackages:
    vitepress: ^1.6.3 => 1.6.3

Additional context

VitePress should by default put the description on the home page, but the title if on any other page as the meta description

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsImprovements or additions to documentationwont fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions