Skip to content

Correct schema for attachment pages for non-image formats #20115

@monbauza

Description

@monbauza

Moved from https://yoast.atlassian.net/browse/IM-2032
Reporter: @jonoalderson

Description

When an attachment page represents a non-image (e.g., a txt file or video), our schema output is incorrect.

E.g., an uploaded txt file generates the following output. Note that the thumbnailUrl property of the WebPage is blank, and the ImageObject (referenced by the primaryImageOfPage and image properties of the WebPage) is ‘empty’.

{
      "@type": "WebPage",
      "@id": "http://blank-test.local/wp-content/uploads/2022/09/test.txt",
      "url": "http://blank-test.local/wp-content/uploads/2022/09/test.txt",
      "name": "test - blank test",
      "isPartOf": {
        "@id": "http://blank-test.local/#website"
      },
      "primaryImageOfPage": {
        "@id": "http://blank-test.local/wp-content/uploads/2022/09/test.txt#primaryimage"
      },
      "image": {
        "@id": "http://blank-test.local/wp-content/uploads/2022/09/test.txt#primaryimage"
      },
      "thumbnailUrl": "",
      "datePublished": "2022-09-27T09:36:02+00:00",
      "dateModified": "2022-09-27T09:36:02+00:00",
      "breadcrumb": {
        "@id": "http://blank-test.local/wp-content/uploads/2022/09/test.txt#breadcrumb"
      },
      "inLanguage": "en-US",
      "potentialAction": [
        {
          "@type": "ReadAction",
          "target": [
            "http://blank-test.local/wp-content/uploads/2022/09/test.txt"
          ]
        }
      ]
    },
    {
      "@type": "ImageObject",
      "inLanguage": "en-US",
      "@id": "http://blank-test.local/wp-content/uploads/2022/09/test.txt#primaryimage",
      "url": "",
      "contentUrl": ""
    },

To address this, we should (on attachment pages only):

  • Determine whether the attachment is a valid image:
    • If it has a suitable mime type (e.g., jpg/png/svg/gif/bmp/webp/avif)
    • If it has a valid url and contentUrl property
  • If not:
    • Don’t output the ImageObject node representing it
    • If that node would have been referenced in the primaryImageOfPage and/or image property of the WebPage, unset those properties.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions