Adding google required paywall schema to article extention
Opened this issue · 0 comments
Hi,
I bought the articles extension, which is great, but because we have a member site google requires us to disclose what parts of an article are behind the paywall. This because we let the google bot though the paywall, so if we don't tell it what is paywalled they will mark us down in page-rank for cloaking.
Read more here: https://developers.google.com/search/docs/data-types/paywalled-content
Getting this working properly and adding it on to the articles extension just about caused my brain to explode—I suck as a coder.
Anyway, I thought it might help others to add this, or something like it, to the Articles extension documentation. Not only will this help member sites, but also anyone wanting to add to the plugins default schema.
There are two parts to this:
This code wraps the part of a wordpress Post that is under the more tag with Div with class paywall, but only if in the MEMBER category (Will need changing for sites that protect all or different parts of a post or don't use categories to control protection)
ID; $test = ''; $paywall = ''; if (in_category('MEMBERS')) { $content = $content.''; $paywall = 'Then this code uses the article plugin filter to add the required schema, again, only in in MEMBERS category:
'WebPageElement','isAccessibleForFree'=> 'False','cssSelector'=>'.paywall'), array('@type' => 'WebPageElement','isAccessibleForFree'=> 'False','cssSelector'=>'.comments-area')); } return $data; } ); ?>As I say, I suck as a coder, so if anyone sees anything stupid in this code that will have unintended consequences, please tell me.
Otherwise, I hope it will help someone else, or at least give them a starting point
John