Update title and add social media metadata
Add Open Graph and Twitter Card metadata for better social sharing Implement dynamic title formatting with site title suffix Add support for social sharing images with fallback to hero image Include default description for better SEO Ensure proper URL handling for both HTTP and HTTPS
This commit is contained in:
parent
7e44e7e132
commit
a558bf3afb
2 changed files with 50 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
|||
title = "Stopp lidelsen"
|
||||
title = "Stopp lidelsen | Pasientene som faller mellom alle stoler"
|
||||
slug = "Forsiden"
|
||||
|
||||
[en]
|
||||
|
|
|
|||
|
|
@ -17,10 +17,56 @@ function getActiveClass($href) { return rtrim(parse_url($_SERVER['REQUEST_URI'],
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<?php if (!empty($metaDescription)): ?>
|
||||
<meta name="description" content="<?= htmlspecialchars($metaDescription) ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
// Prepare social media metadata
|
||||
$siteTitle = 'Stopp lidelsen';
|
||||
$fullTitle = !empty($pageTitle) ? htmlspecialchars($pageTitle) . ' - ' . $siteTitle : $siteTitle;
|
||||
$description = !empty($metaDescription) ? htmlspecialchars($metaDescription) : 'Vi arbeider for at pasienter som kan ha nytte av medisinsk cannabis skal motta likeverdig og trygg behandling med oppfølging fra lege.';
|
||||
$currentUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||
|
||||
// Determine social media image
|
||||
$socialImage = null;
|
||||
if (!empty($socialImageUrl)) {
|
||||
// Use provided social image URL
|
||||
$socialImage = $socialImageUrl;
|
||||
} elseif ($_SERVER['REQUEST_URI'] === '/' || rtrim($_SERVER['REQUEST_URI'], '/') === '') {
|
||||
// Use hero-bg.webp for frontpage
|
||||
$socialImage = '/hero-bg.webp';
|
||||
}
|
||||
|
||||
// Convert relative URLs to absolute for social media
|
||||
if ($socialImage && !str_starts_with($socialImage, 'http')) {
|
||||
$socialImage = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $socialImage;
|
||||
}
|
||||
?>
|
||||
|
||||
<title><?= $fullTitle ?></title>
|
||||
|
||||
<!-- Standard metadata -->
|
||||
<meta name="description" content="<?= $description ?>">
|
||||
<meta name="fediverse:creator" content="@stopplidelsen@oslo.town">
|
||||
|
||||
<!-- Open Graph metadata (Facebook, Mastodon, etc.) -->
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:site_name" content="<?= $siteTitle ?>">
|
||||
<meta property="og:title" content="<?= $fullTitle ?>">
|
||||
<meta property="og:description" content="<?= $description ?>">
|
||||
<meta property="og:url" content="<?= htmlspecialchars($currentUrl) ?>">
|
||||
<?php if ($socialImage): ?>
|
||||
<meta property="og:image" content="<?= htmlspecialchars($socialImage) ?>">
|
||||
<meta property="og:image:alt" content="<?= $fullTitle ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Twitter Card metadata -->
|
||||
<meta name="twitter:card" content="<?= $socialImage ? 'summary_large_image' : 'summary' ?>">
|
||||
<meta name="twitter:title" content="<?= $fullTitle ?>">
|
||||
<meta name="twitter:description" content="<?= $description ?>">
|
||||
<?php if ($socialImage): ?>
|
||||
<meta name="twitter:image" content="<?= htmlspecialchars($socialImage) ?>">
|
||||
<meta name="twitter:image:alt" content="<?= $fullTitle ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<link rel="stylesheet" href="<?= $cssUrl ?>?v=<?= $cssHash ?>">
|
||||
<?php if (!empty($pageCssUrl)): ?>
|
||||
<link rel="stylesheet" href="<?= $pageCssUrl ?>?v=<?= $pageCssHash ?? '' ?>">
|
||||
|
|
@ -28,7 +74,6 @@ function getActiveClass($href) { return rtrim(parse_url($_SERVER['REQUEST_URI'],
|
|||
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
||||
<link rel="icon" href="/favicon.png" type="image/png">
|
||||
<link href="/app/fonts/pt-serif/pt-serif.css" rel="stylesheet">
|
||||
<title><?= htmlspecialchars($pageTitle ?? 'Stopp lidelsen') ?></title>
|
||||
</head>
|
||||
|
||||
<body class="<?php if (isset($dirName)) echo 'section-' . $dirName . ' '; ?><?php if (isset($pageName)) echo 'page-' . $pageName; ?>">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue