// === Urban Haggis Stays: Fix VacationRental Schema for Listings === add_action('wp_head', 'uhs_inject_listing_schema', 5); function uhs_inject_listing_schema() { if (!is_singular('listing')) return; $post_id = get_the_ID(); $slug = get_post_field('post_name', $post_id); $listings = [ 'bruce-on-the-row-historic-elegance-near-edinburgh' => [ 'streetAddress' => '83A New Row', 'postalCode' => 'KY12 7DZ', 'addressLocality' => 'Dunfermline', 'identifier' => 'UHS-BRUCE-001', ], 'the-lang-toun-bothy-by-the-sea-near-edinburgh' => [ 'streetAddress' => '15 Alexandra Street', 'postalCode' => 'KY1 1HG', 'addressLocality' => 'Kirkcaldy', 'identifier' => 'UHS-LANGBOTHY-002', ], 'luxury-seaview-gated-penthouse-near-edinburgh' => [ 'streetAddress' => '3 Allen Court', 'postalCode' => 'KY1 1HD', 'addressLocality' => 'Kirkcaldy', 'identifier' => 'UHS-PENTHOUSE-003', ], 'luxurious-house-gated-sea-view-near-edinburgh' => [ 'streetAddress' => '26 Allen Court', 'postalCode' => 'KY1 1HD', 'addressLocality' => 'Kirkcaldy', 'identifier' => 'UHS-LUXHOUSE-004', ], ]; if (!isset($listings[$slug])) return; $info = $listings[$slug]; $gallery_ids = get_post_meta($post_id, 'listing_gallery', true); $images = []; if (!empty($gallery_ids) && is_array($gallery_ids)) { foreach (array_slice($gallery_ids, 0, 8) as $img_id) { $src = wp_get_attachment_url($img_id); if ($src) $images[] = $src; } } if (empty($images)) { $thumb = get_the_post_thumbnail_url($post_id, 'full'); if ($thumb) $images[] = $thumb; } $url = get_permalink($post_id); $name = get_the_title($post_id); $description = get_the_excerpt($post_id) ?: wp_trim_words(strip_tags(get_the_content()), 40); $price = get_post_meta($post_id, 'price', true); $bedrooms = (int) get_post_meta($post_id, 'bedrooms', true); $bathrooms = (int) get_post_meta($post_id, 'bathrooms', true); $guests = (int) get_post_meta($post_id, 'guests_number', true); $lat = get_post_meta($post_id, 'lat', true); $lng = get_post_meta($post_id, 'lng', true); $schema = [ '@context' => 'https://schema.org', '@type' => ['LodgingBusiness', 'VacationRental'], '@id' => $url, 'identifier' => $info['identifier'], 'name' => $name, 'description' => $description, 'url' => $url, 'image' => count($images) === 1 ? $images[0] : $images, 'additionalType' => 'https://schema.org/LodgingBusiness', 'containsPlace' => [ '@type' => 'Accommodation', 'name' => $name, 'numberOfRooms' => $bedrooms, 'occupancy' => ['@type' => 'QuantitativeValue', 'maxValue' => $guests], ], 'address' => [ '@type' => 'PostalAddress', 'streetAddress' => $info['streetAddress'], 'addressLocality' => $info['addressLocality'], 'addressRegion' => 'Fife', 'postalCode' => $info['postalCode'], 'addressCountry' => 'GB', ], 'geo' => ['@type' => 'GeoCoordinates', 'latitude' => $lat, 'longitude' => $lng], 'priceRange' => 'GBP' . $price . ' per night', 'numberOfRooms' => $bedrooms, 'checkinTime' => 'T15:00', 'checkoutTime' => 'T11:00', 'petsAllowed' => false, 'offers' => [ '@type' => 'Offer', 'price' => $price, 'priceCurrency' => 'GBP', 'priceSpecification' => ['@type' => 'UnitPriceSpecification', 'price' => $price, 'priceCurrency' => 'GBP', 'unitText' => 'NIGHT'], ], 'amenityFeature' => [ ['@type' => 'LocationFeatureSpecification', 'name' => 'Bedrooms', 'value' => $bedrooms], ['@type' => 'LocationFeatureSpecification', 'name' => 'Bathrooms', 'value' => $bathrooms], ['@type' => 'LocationFeatureSpecification', 'name' => 'Maximum Guests', 'value' => $guests], ['@type' => 'LocationFeatureSpecification', 'name' => 'Free WiFi', 'value' => true], ], 'touristType' => ['Tourists', 'Business Travellers', 'Golfers', 'Families'], 'provider' => ['@type' => 'Organization', 'name' => 'Urban Haggis Stays', 'url' => 'https://urbanhaggisstays.co.uk'], ]; echo '