prepare('SELECT * FROM products WHERE url_slug = ?'); $stmt->execute([$slug]); $product = $stmt->fetch(PDO::FETCH_ASSOC); } catch (PDOException $e) { error_log('Failed to fetch product: ' . $e->getMessage()); } } // If no product is found, send a 404 response if (!$product) { http_response_code(404); require_once __DIR__ . '/includes/header.php'; echo '
'; require_once __DIR__ . '/includes/footer.php'; exit; } // --- SEO & Page Variables --- $seo_title = $product['seo_title']; $seo_meta_description = $product['seo_meta_description']; $canonical_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}" . $product['canonical_url']; $og_title = $product['og_title']; $og_description = $product['og_description']; $og_image = $product['og_image']; // Assuming this is a full URL $og_type = 'product'; $images = json_decode($product['images'], true); // JSON-LD Schema for Product $schema = [ '@context' => 'https://schema.org', '@type' => 'Product', 'name' => $product['name'], 'description' => $product['description'], 'image' => $images, // Array of image URLs 'offers' => [ '@type' => 'Offer', 'priceCurrency' => 'USD', // Change as needed 'price' => '0', // Add a price column if you have one 'availability' => 'https://schema.org/InStock' ] ]; require_once __DIR__ . '/includes/header.php'; ?>