Hi,
I'm experiencing this issue with 7.x-1.0-rc1 version.
I can see all the JSON+LD markup generated but it's wrapped by a script tag without the application type, thus when tested with Google tool it's not recognized. The valdiate icon doesn't do anything.
Adding the type="application/ld+json" manually on the tool (left side) I can click on the Validate icon and see all the attributed on the right side.
I inspected the source code of the module and I can see the renderArrayJsonLd function on line 53 from file src/SchemaMetatagManager.php including in line 58 the '#attributes' => ['type' => 'application/ld+json'].
public static function renderArrayJsonLd($jsonld) {
return [
'#type' => 'html_tag',
'#tag' => 'script',
'#value' => $jsonld,
'#attributes' => ['type' => 'application/ld+json'],
];
}
Any clue?
Thanks.
Comments
Comment #2
progga commentedI am facing the same problem. Turned out that the Zen theme, which we are using as the base theme, is stripping out the '#attributes' item :(
Comment #3
damienmckennaUgh. Maybe submit a feature request with a patch that makes that optional using a variable, then some documentation could be added to Schema Metatag to apply the patch and hardcode the variable to disable the feature?
Comment #4
damienmckennaWorking on a fix..
Comment #5
damienmckennaThis appears to solve the problem in my limited testing. Note: I also uploaded a similar patch for Zen theme itself.
Comment #6
damienmckennaComment #7
progga commentedPatch works as expected. I have some reservations about the effect of the patch though. While it is solving the immediate problem by letting us have *application/ld+json* as the script type, we still can't use any other type. MDN suggests other values (e.g. *module*) are acceptable. So if anyone tries any value other than *text/ng-template* or *application/ld+json*, they will be stuck and will most likely add another ticket to this project's issue queue.
It appears to me that the goal of Zen's html_tag process function was to omit the *application/javascript* type as that is the default for script tags in HTML *5*. So if we just drop *application/javascript* and *keep* everything else, that could save some potential future trouble regarding the script tag.
Comment #8
karens commentedThis is a Zen problem, and Damien created an issue and patch on that queue to fix it. I think it's better to leave the fix there. And there people can discuss other reasons to include or exclude various types. For reference, the patch is at https://www.drupal.org/project/zen/issues/2934644.
I am going to let Zen fix this, it feels pretty heavy-handed to try to fix a theme problem here. I will also add a note to the project page pointing to that patch.
Rather than marking this fixed or won't fix, which will close this issue, I'll mark it postponed so the issue stays in the queue where it can be found by others.
Comment #9
damienmckennaThat's complete valid, thanks progga and KarenS.
Comment #10
christophweber commentedTurns out this issue is more widespread. Our theme is based on Mothership and does the same as Zen. I had to wrap/kill the preprocess function with Damien's if clause in both, Mothership's template.php and our subtheme's own template.php. Updating the D7 README.txt accordingly.
Comment #11
chicagomom commentedThis also appears to be happening with the Aurora theme's template.php:
Comment #12
christophweber commentedYes, looks like many themers took the blog post in the comment of this code snippet to heart, and that code is overly aggressive.
The README for the released version, as well as current HEAD mentions this and points to two issues where folks can copy and paste code examples from to fix the issue. Not a great solution.
Nicole Sciacca's (nsciacca) metatag_jsonld sandbox project had this theme callback to explicitly set the right type and it has never failed me. I'm not enough of a themer to determine whether schema_metatag could also do an endrun around aggressive settings in template.php.
'; $output .= $variables['element']['#value']; $output .= "/**
* Theme callback for a json-ld tag.
*/
function theme_metatag_jsonld($variables) {
$result = json_decode($variables['element']['#value']);
if (json_last_error() === JSON_ERROR_NONE) {
$output = '
\n";
return $output;
}
return FALSE;
}
Comment #13
chicagomom commentedAs an fyi, the Aurora theme has a "Prune HTML tags" checkbox in its theme settings that enables/disables this trimming for all tags.
The HTML5 Tools module also has a "Simplify javascript tags" checkbox that strips out all type attributes for Javascript tags when enabled.
Comment #14
christophweber commentedThanks @chicagomom, I updated the known issues section of https://www.drupal.org/docs/7/modules/schemaorg-metatag/basic-usage.
Comment #15
amir_razavi commentedI have rebuilt the #5 with the latest version of the module.
Comment #16
amir_razavi commentedComment #17
christophweber commentedThanks @amir_razavi. I am closing this issue again, since we all agreed that Zen and other themes need to fix the problem, rather than schema_metatag module.
Comment #18
anybodyThe same problem also exists for the beloved AdaptiveTheme. I guess that should also be added to the module description page for Drupal 7:
process.inc, line 47ff.: