// Get current URL path $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $segments = explode('/', trim($path, '/')); // Validate URL depth if (count($segments) < 2) return; // Extract structure, state, city $state_slug = $segments[0]; // e.g., prefab-barns-in-ohio-oh $city_slug = $segments[1]; // e.g., prefab-barns-in-chillicothe-oh // Helper to convert slugs to titles function slugToTitle($slug) { return ucwords(str_replace('-', ' ', $slug)); } // Derive names $structure_type = preg_replace('/-in-.*/', '', $state_slug); // e.g., "prefab-barns" $state_name = preg_replace('/.*-in-/', '', $state_slug); // e.g., "ohio-oh" $city_name = preg_replace('/.*-in-/', '', $city_slug); // e.g., "chillicothe-oh" // Final labels $structure_label = slugToTitle($structure_type); $state_label = slugToTitle(preg_replace('/-[a-z]{2}$/', '', $state_name)); $city_label = slugToTitle(preg_replace('/-[a-z]{2}$/', '', $city_name)); $site = 'https://daytonbarns.com'; $breadcrumbs = [ [ '@type' => 'ListItem', 'position' => 1, 'name' => 'Home', 'item' => $site ], [ '@type' => 'ListItem', 'position' => 2, 'name' => "$structure_label in $state_label", 'item' => "$site/$state_slug/" ], [ '@type' => 'ListItem', 'position' => 3, 'name' => "$structure_label in $city_label", 'item' => "$site/$state_slug/$city_slug/" ] ]; $breadcrumbJson = [ '@context' => 'https://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => $breadcrumbs ]; // Output JSON-LD echo '';