<?php
require_once __DIR__ . '/functions.php';
/**
* Render <title>, meta description/keywords, canonical, Open Graph, Twitter Card,
* and Organization JSON-LD schema. Call once inside each page's <head>.
*/
function render_seo(string $title = '', string $description = '', string $image = '', string $type = 'website'): void {
$s = get_settings();
$siteName = $s['site_name'] ?? 'Excellent Education & Counselling Services Pvt. Ltd.';
$finalTitle = $title !== '' ? $title . ' | ' . $siteName : ($s['meta_title'] ?? $siteName);
$finalDesc = $description !== '' ? $description : ($s['meta_description'] ?? '');
$finalImage = $image !== '' ? resolve_image($image) : resolve_image($s['og_image'] ?? '', SITE_URL . '/assets/img/logo-full.png');
$canonical = SITE_URL . ($_SERVER['REQUEST_URI'] ?? '/');
echo '<title>' . e($finalTitle) . "</title>\n";
echo '<meta name="description" content="' . e($finalDesc) . "\">\n";
if (!empty($s['meta_keywords'])) {
echo '<meta name="keywords" content="' . e($s['meta_keywords']) . "\">\n";
}
echo '<link rel="canonical" href="' . e($canonical) . "\">\n";
echo '<meta property="og:site_name" content="' . e($siteName) . "\">\n";
echo '<meta property="og:title" content="' . e($finalTitle) . "\">\n";
echo '<meta property="og:description" content="' . e($finalDesc) . "\">\n";
echo '<meta property="og:type" content="' . e($type) . "\">\n";
echo '<meta property="og:url" content="' . e($canonical) . "\">\n";
echo '<meta property="og:image" content="' . e($finalImage) . "\">\n";
echo '<meta name="twitter:card" content="summary_large_image">' . "\n";
echo '<meta name="twitter:title" content="' . e($finalTitle) . "\">\n";
echo '<meta name="twitter:description" content="' . e($finalDesc) . "\">\n";
echo '<meta name="twitter:image" content="' . e($finalImage) . "\">\n";
echo '<link rel="icon" type="image/png" href="' . e(resolve_image($s['favicon'] ?? 'assets/img/logo-icon.png')) . "\">\n";
$schema = [
'@context' => 'https://schema.org',
'@type' => 'EducationalOrganization',
'name' => $siteName,
'url' => SITE_URL,
'logo' => resolve_image($s['logo_full'] ?? ''),
'address' => [
'@type' => 'PostalAddress',
'streetAddress' => $s['address'] ?? '',
'addressCountry' => 'NP',
],
'telephone' => $s['phone'] ?? '',
'email' => $s['email'] ?? '',
'sameAs' => array_values(array_filter([
$s['facebook_url'] ?? '', $s['instagram_url'] ?? '', $s['youtube_url'] ?? '', $s['linkedin_url'] ?? '',
], fn($u) => $u && $u !== '#')),
];
echo '<script type="application/ld+json">' . json_encode($schema, JSON_UNESCAPED_SLASHES) . "</script>\n";
}