/** * Plugin Name: XPR Press Release JSON-LD + Tracking (MU) * Description: Outputs PR front + PR story JSON-LD and tracking for /press-release/ and /press-release/story/*. * Version: 1.0.0 */ if (!defined('ABSPATH')) exit; /** * Per-site configuration. * Add more hosts as needed. */ function xpr_pr_site_config(): array { return [ 'azcentral.xpr-gannett.com' => [ 'canonical_host' => 'azcentral.com', 'publisher_name' => 'AZCentral | The Arizona Republic', 'publisher_logo' => 'https://azcentral.com/sitelogos/m-oc.svg', 'ispartof_name' => 'AZCentral | The Arizona Republic - Unlimited Digital Access', 'product_id' => 'azcentral.com:standard', // Required front fields 'front_thumbnail_url' => 'https://azcentral.xpr-gannett.com/wp-content/uploads/sites/43/2025/05/image-14.png', 'front_date_published' => '2025-04-29T21:15:50+00:00', ], // Add more hosts here as needed ]; } function xpr_current_host(): string { $host = $_SERVER['HTTP_HOST'] ?? ''; $host = strtolower(trim($host)); return preg_replace('/:\d+$/', '', $host); } function xpr_get_cfg(): array { $host = xpr_current_host(); $map = xpr_pr_site_config(); return $map[$host] ?? []; } function xpr_to_canonical_url(string $url, array $cfg): string { if (empty($url) || empty($cfg['canonical_host'])) return $url; $host = xpr_current_host(); return preg_replace( '#^https?://' . preg_quote($host, '#') . '#i', 'https://' . $cfg['canonical_host'], $url ); } function xpr_is_pr_front(): bool { $uri = $_SERVER['REQUEST_URI'] ?? ''; $path = parse_url($uri, PHP_URL_PATH) ?: $uri; return rtrim($path, '/') === '/press-release'; } function xpr_is_pr_story(): bool { if (!is_singular('post')) return false; $uri = $_SERVER['REQUEST_URI'] ?? ''; $path = parse_url($uri, PHP_URL_PATH) ?: $uri; return (strpos($path, '/press-release/story/') !== false); } add_action('wp_head', function () { $cfg = xpr_get_cfg(); // FRONT PAGE JSON-LD if (xpr_is_pr_front() && !empty($cfg)) { $front_url = xpr_to_canonical_url(home_url('/press-release/'), $cfg); $data = [ '@context' => 'https://schema.org', '@type' => 'WebPage', '@id' => $front_url, 'url' => $front_url, 'name' => 'Press Release – ' . $cfg['publisher_name'], 'primaryImageOfPage' => [ '@id' => $front_url . '#primaryimage' ], 'image' => [ '@id' => $front_url . '#primaryimage' ], 'thumbnailUrl' => xpr_to_canonical_url($cfg['front_thumbnail_url'], $cfg), 'datePublished' => $cfg['front_date_published'], 'breadcrumb' => [ '@id' => $front_url . '#breadcrumb' ], 'inLanguage' => 'en-US', 'potentialAction' => [[ '@type' => 'ReadAction', 'target' => [$front_url] ]], 'keywords' => [ 'type:front', 'ssts:press release' ], 'isAccessibleForFree' => true, 'isPartOf' => [ '@type' => ['CreativeWork', 'Product'], 'name' => $cfg['ispartof_name'], 'productID' => $cfg['product_id'] ], 'publisher' => [ '@type' => 'Organization', 'name' => $cfg['publisher_name'], 'logo' => $cfg['publisher_logo'] ] ]; echo ''; } // STORY PAGE JSON-LD + TRACKING if (xpr_is_pr_story() && !empty($cfg)) { $post_id = get_the_ID(); $title = get_the_title($post_id); $permalink = xpr_to_canonical_url(get_permalink($post_id), $cfg); $thumb_raw = get_the_post_thumbnail_url($post_id, 'full'); $thumb = xpr_to_canonical_url($thumb_raw ?: '', $cfg); $jsonld = [ '@context' => 'https://schema.org', '@type' => 'NewsArticle', '@id' => $permalink, 'url' => $permalink, 'headline' => wp_strip_all_tags($title), 'thumbnailUrl' => $thumb, 'datePublished' => get_the_date(DATE_W3C, $post_id), 'dateModified' => get_the_modified_date(DATE_W3C, $post_id), 'inLanguage' => 'en-US', 'potentialAction' => [[ '@type' => 'ReadAction', 'target' => [$permalink] ]], 'articleSection' => 'press release', 'publisher' => [ '@type' => 'Organization', 'name' => $cfg['publisher_name'], 'logo' => [ '@type' => 'ImageObject', 'url' => $cfg['publisher_logo'] ] ], 'author' => [ '@type' => 'Organization', 'name' => 'pressadvantage' ], 'keywords' => [ 'access:free', 'ssts:press release', 'type:story' ], 'isAccessibleForFree' => true, 'isPartOf' => [ '@type' => ['CreativeWork', 'Product'], 'name' => $cfg['ispartof_name'], 'productID' => $cfg['product_id'] ] ]; echo ''; } }, 99);