Hi @linformatiquelabs
Thanks for your kind words and for your detailed feedback. It is much appreciated.
Currently, the main Schema.org entity of a page can only be customized programmatically for maximum flexibility. Please check the following example:
function amt_set_custom_schemaorg_entity( $default ) {
if ( is_page('about') ) {
return 'AboutPage';
} elseif ( is_page('contact') ) {
return 'ContactPage';
} elseif ( is_singular('news_post_type') ) {
return 'NewsArticle';
} elseif ( is_singular('blog_post_type') ) {
return 'BlogPosting';
} elseif ( is_page() ) {
return 'WebPage';
}
return $default; // Article
}
add_filter( 'amt_schemaorg_object_main', 'amt_set_custom_schemaorg_entity' );
This can be placed in the theme’s functions.php or in a custom plugin.
I’ll need to think more about the idea of adding a configuration option about this in the web interface. The problem is that its functionality will be very limited and in most cases the user will revert back to setting the main schema.org entity programmatically.
About creating an add-on for the official AMP plugin, this is going to need some more thought as it is going to require maintenance and time.
I’ll keep you updated. Thanks again for the detailed feedback.
Best Regards,
George
Hi @linformatiquelabs
I just noticed that there is a redirection issue when accessing this topic from another device. The browser complains that the topic is not redirecting properly. Do you encounter this problem too?
Maybe the special characters « and » in the topic title are causing this. Do you mind if I ask a moderator to check it and possibly modify the topic title?
George
Added more info about the redirection issue here.
Hi,
Thank you very much for your answer
I just tested this code in the theme, but unfortunately it does not work, here is the link where there is the error: http://www.efemme.org/31-francaises-simulent-49-ont-difficultes-a-atteindre-lorgasme.html/amp
the link to test: https://developers.google.com/structured-data/testing-tool/
For special characters ” in the title of this discussion, the link opens normal for me on Chrome and Firefox (I use an OS X system).
I tried to see the option to change the title of this publication, but I do not see this option, I do not think this is possible.
Best Regards,
Hicham
Hi Hicham,
Have you turned on the generation of schema.org metadata in the Add-Meta-Tags settings (Settings -> Metadata)?
The JSON+LD data I see is most probably generated by the AMP plugin.
If I enable the option “Automatically generate and embed Schema.org Microdata.” the meta tags “article” will duplicate, it gives “Article 2”
Error with the AMP plugin : The image.width attribute has an incorrect value. (L’attribut image.width possède une valeur incorrecte.) And it generates “blogposting”, normally it must give structure “article”, not “blog posting”
If I enable the option “Automatically generate and embed Schema.org Microdata.” the meta tags “article” will duplicate, it gives “Article 2”
This is the expected result.
In order to deactivate the schema.org metadata generated by the AMP plugin you will possibly have to attach a filtering function to the amp_post_template_metadata hook and return an empty array. Please note that this is untested. See more here: https://github.com/Automattic/amp-wp#schemaorg-json-metadata
As a general principal Add-Meta-Tags never affects the functionality of other plugins, so any customization of the AMP output must be done by the user. However, if you need any help, please feel free to ask your questions here or on Github.
Best Regards,
George
Example:
function xyz_amp_modify_json_metadata( $metadata, $post ) {
return array();
}
add_filter( 'amp_post_template_metadata', 'xyz_amp_modify_json_metadata', 10, 2 );
Please note this is untested.
Thank you for your reply.
Where do I have to put this code ?
To deactivate « BlogPosting » Structured data from AMP Plugin, I deleted the code below from this file « class-amp-post-template.php » :
$metadata = array(
'@context' => 'http://schema.org',
'@type' => 'BlogPosting',
'mainEntityOfPage' => $this->get( 'canonical_url' ),
'publisher' => array(
'@type' => 'Organization',
'name' => $this->get( 'blog_name' ),
),
'headline' => $post_title,
'datePublished' => date( 'c', $post_publish_timestamp ),
'dateModified' => date( 'c', $post_modified_timestamp ),
'author' => array(
'@type' => 'Person',
'name' => $post_author->display_name,
),
);
$site_icon_url = $this->get( 'site_icon_url' );
$metadata['publisher']['logo'] = array(
'@type' => 'ImageObject',
'url' => 'http://www.efemme.org/logo.png',
'height' => auto,
'width' => auto,
);
$image_metadata = $this->get_post_image_metadata();
if ( $image_metadata ) {
$metadata['image'] = $image_metadata;
}
$this->add_data_by_key( 'metadata', apply_filters( 'amp_post_template_metadata', $metadata, $this->post ) );
How to add the structured data «Article» or «NewsArticle» in post with AMP Plugin, for a theme who has «NewsArticle» in his structured data? Is it be possible to add this feature with the plugin «add meta Data» or with a specific code?
The solution is with this code:
add_filter( 'amp_post_template_metadata', 'xyz_amp_modify_json_metadata', 10, 2 );
function xyz_amp_modify_json_metadata( $metadata, $post ) {
$metadata['@type'] = 'NewsArticle';
$metadata['publisher']['logo'] = array(
'@type' => 'ImageObject',
'url' => get_template_directory_uri() . '/images/my-amp-metadata-logo.png',
'height' => 60,
'width' => 600,
);
return $metadata;
}
in the link you gave me: https://github.com/Automattic/amp-wp#schemaorg-json-metadata
But in structured data testing tool i have error validation : “The attribute image.width has an invalid value.”
Anyone know whats wrong ?
Thank you
Hi Hicham,
It seems I missed your last posts.
The snippet above modifies the metadata generated by the AMP plugin. I’ll be checking it more closely at some later time tonight and keep you updated.
George
Hicham, you need to add quotes to the w and h values.
‘height’ => “113”,
‘width’ => “800”,