Open hans-olson opened 1 year ago
Fields:
@hans-olson you can fill others fields
Also for more information:
https://developers.google.com/search/docs/appearance/structured-data/event https://wordpress.org/support/topic/google-search-console-missing-attributes/page/2/
@hans-olson
Example of code:
add_action('wp_head', 'add_custom_event_schema');
function add_custom_event_schema() {
if (is_singular('event')) { // Проверьте, что это страница события
$event_attendance_mode = get_post_meta(get_the_ID(), 'event_attendance_mode', true);
$event_performer = get_post_meta(get_the_ID(), 'event_performer', true);
$event_ticket_url = get_post_meta(get_the_ID(), 'event_ticket_url', true);
$event_price = get_post_meta(get_the_ID(), 'event_price', true);
$event_currency = get_post_meta(get_the_ID(), 'event_currency', true);
$event_image = get_the_post_thumbnail_url(get_the_ID(), 'full');
$event_organizer = get_post_meta(get_the_ID(), 'event_organizer', true);
$event_organizer_url = get_post_meta(get_the_ID(), 'event_organizer_url', true);
if ($event_attendance_mode && $event_performer && $event_ticket_url && $event_price && $event_currency && $event_image && $event_organizer && $event_organizer_url) {
?>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Event",
"eventAttendanceMode": "https://schema.org/<?php echo esc_html($event_attendance_mode); ?>",
"performer": {
"@type": "Person",
"name": "<?php echo esc_html($event_performer); ?>"
},
"offers": {
"@type": "Offer",
"url": "<?php echo esc_url($event_ticket_url); ?>",
"price": "<?php echo esc_html($event_price); ?>",
"priceCurrency": "<?php echo esc_html($event_currency); ?>"
},
"image": "<?php echo esc_url($event_image); ?>",
"organizer": {
"@type": "Organization",
"name": "<?php echo esc_html($event_organizer); ?>",
"url": "<?php echo esc_url($event_organizer_url); ?>"
}
}
</script>
<?php
}
}
}
?>
Google Search Console has identified that your site is affected by 7 Events structured data issue(s). The following issues were found on your site.
Top non-critical issues**
**Non-critical issues are suggestions for improvement, but do not prevent the page or feature from appearing on Google. Some of these issues can affect your appearance on Search; some might be reclassified as critical issues in the future.
We recommend that you fix these issues when possible to enable the best experience and coverage in Google Search.