diesdasdigital / kirby-meta-knight

🔍 Meta Knight – SEO & Social Media Sharing Plugin for Kirby.
MIT License
109 stars 18 forks source link

Google Search Console "Reference to non-existent item" #53

Open dw-herrmann opened 2 years ago

dw-herrmann commented 2 years ago

Hi there,

my kirby site, in which meta knignt, creates an error in Google Search Console. <style itemscope itemtype="https://schema.org/WebSite" itemref="schema_name schema_description schema_image"></style> creates the error "Unparsable structured data/Reference to non-existent item".

How can I or meta knight fix this problem? By research, I didn't quite understand it.

Thanks in advance!

marc22761 commented 2 years ago

I'm having the same issue.

lexislav commented 2 years ago

I am also having this issue. Is it possible to customize meta knight template and remove this line?

afbora commented 2 years ago

@jonathanmuth We are experiencing this issue with several of our customers. What do you think about getting rid of this line or putting a custom option for this? I can create a PR if you see fit 👍

'diesdasdigital.meta-knight' => [
    'websiteItemscope' => false,
],
Messa1 commented 2 years ago

Any Update?

Jayshua commented 1 year ago

Here's a full explanation of what's going on for anyone who is interested. A quick fix is at the end.

<style itemscope itemtype="https://schema.org/WebSite" itemref="schema_name schema_description schema_image"></style> is meant to describe info about the web site so that Google & other tools can extract the name, description and a representative image of the website for machine use. (Like generating those special cards that show up in Google searches sometimes, or inserting a picture when you send a link to someone in Messenger, WhatsApp, Telegram, etc.)

Don't get too hung up on it being a <style> tag. It could be any tag, I'm not sure why MetaKnight decided to use a <style> tag. I probably would have used a <meta> tag.

That brings us to this bug. <style itemscope itemtype="https://schema.org/WebSite" itemref="schema_name schema_description schema_image"></style> is trying to provide information about your website (to Google, Bing, Facebook, etc.) It says "I'm describing a WebSite, find elements with the ids "schema_name, schema_description and schema_image" for more info.

You'll probably find a meta tag like this nearby in the source: <meta id="schema_name" itemprop="name" content="..."> This tag is providing data for the name property defined in https://schema.org/WebSite.

There's probably a meta tag with the id "schema_description" and the itemprop "description" nearby as well.

There's probably not a tag with the id "schema_image" in your source, since the default meta_information snippet provided by MetaKnight only produces that element if you define a meta_image field on the page or site.

The correct fix is to only include the schema_image id in the itemref list if there is actually an element with the schema_image id on the page.

You probably do not want to remove the <style itemscope... line altogether, since that would make bots unable to extract useful info about your website.

A quick fix is to copy the kirby-meta-knight/snippets/meta_information.php file into your site/snippets folder and replace this line:

<style itemscope itemtype="https://schema.org/WebSite" itemref="schema_name schema_description schema_image"></style>

With this:

<style itemscope itemtype="https://schema.org/WebSite" itemref="schema_name schema_description <?= ($page->meta_image()->toFile() ?? $site->meta_image()->toFile()) ? 'schema_image' : null ?>"></style>

This will only include the schema_image id in the itemref id list if there's actually a schema_image to find.

renestalder commented 1 year ago

Could we get that in a PR?

Jayshua commented 1 year ago

@renestalder I don't submit PRs without confirmation from the maintainer that they want the change/fix. It just wastes time if they want to go in a different direction with the code. If you'd like to take the time to do it though, be my guest.

renestalder commented 1 year ago

There you go: https://github.com/diesdasdigital/kirby-meta-knight/pull/69

@Jayshua I hope it's okay I've set you as co-author in the commit because I basically did nothing else than verifying your patch and putting it in a PR. It's you that did the work.