// OG tags for sharing a specific timeline event via /timeline/?event=ID add_action('wp_head', function(){ if (!is_page()) return; // limit to timeline page to avoid side effects $is_timeline = false; $obj = get_queried_object(); if ($obj && !empty($obj->post_name)) { $is_timeline = ($obj->post_name === 'timeline'); } if (!$is_timeline) return; $eid = isset($_GET['event']) ? intval($_GET['event']) : (isset($_GET['event_id']) ? intval($_GET['event_id']) : 0); if ($eid <= 0) return; global $wpdb; $tbl = $wpdb->prefix . 'sh_timeline_events'; $ev = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$tbl} WHERE id = %d LIMIT 1", $eid)); if (!$ev) return; if (!empty($ev->event_id)) { $orig = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$tbl} WHERE id = %d LIMIT 1", intval($ev->event_id))); if ($orig) { $ev = $orig; } } $title = !empty($ev->title) ? wp_strip_all_tags($ev->title) : 'Δημοσίευση'; $desc = !empty($ev->description) ? wp_strip_all_tags($ev->description) : ''; $img = ''; if (!empty($ev->event_image_id)) { $img = wp_get_attachment_image_url(intval($ev->event_image_id), 'large'); if (function_exists('sh_maybe_private_media_url')) { $img = sh_maybe_private_media_url($img); } } // Absolute og:url pointing to sharable query URL (hash is ignored by crawlers) $og_url = add_query_arg('event', $eid, home_url('/timeline/')); // Output minimal OG/Twitter tags only when image/title available echo "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; if ($desc) { echo '' . "\n"; } if ($img) { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } }, 1);