[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] [BP][FIX][UX] SEO: Use absolute URLs for canonical and alternate hreflang links in wiki pages
"Olivier Kango \(@olivierkango\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <69dd64eb31020_3b18e4446983f@gitlab-sidekiq-low-urgency-cpu-bound-v2-7bd84b4764-98d59.mail> |
Olivier Kango pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki
Commits:
83196a13 by Olivier Kango at 2026-04-13T23:41:46+02:00
[BP][FIX][UX] SEO: Use absolute URLs for canonical and alternate hreflang links in wiki pages
---
* [BP][FIX][UX] SEO: Use absolute URLs for canonical and alternate hreflang links in wiki pages
---
* [FIX][UX] SEO: Use absolute URLs for canonical and alternate hreflang links in wiki pages
---
* [FIX] - Expected 1 space after NOT operator error
* [FIX] Use absolute URLs for hreflang links and avoid duplicate canonicals
* [FIX][SEO] Use absolute URLs for canonical and hreflang links in wiki pages
See merge request tikiwiki/tiki!8443
(cherry picked from commit e3b5a9ab069ae6e4838cf2025c473f7a8ac17633)
See merge request tikiwiki/tiki!8707
(cherry picked from commit 120c3791aeb5e0b1903832d3de848313ea875b62)
See merge request tikiwiki/tiki!10013
- - - - -
1 changed file:
- lib/wiki/renderlib.php
Changes:
=====================================
lib/wiki/renderlib.php
=====================================
@@ -212,12 +212,30 @@ class WikiRenderer
$headerlib = TikiLib::lib('header');
$links = [];
+
+ $wikilib = TikiLib::lib('wiki');
+ global $base_url;
+ $base = rtrim((string) $base_url, '/');
+
+ $selfHref = $wikilib->sefurl($this->page);
+ if (! preg_match('~^https?://~i', $selfHref)) {
+ $selfHref = $base . '/' . ltrim($selfHref, '/');
+ }
+
+ $links[] = '<link rel="alternate" hreflang="' . htmlspecialchars(strtolower($this->info['lang']), ENT_QUOTES, 'UTF-8') . '" href="' . htmlspecialchars($selfHref, ENT_QUOTES, 'UTF-8') . '">';
+
foreach ($this->trads as $trad) {
if ($trad['lang'] != $this->info['lang']) {
- $links[] = '<link rel="alternate" href="tiki-index.php?page=' . $trad['objName'] . '" hreflang="' . $trad['lang'] . '">';
+ $tradHref = $wikilib->sefurl($trad['objName']);
+ if (! preg_match('~^https?://~i', $tradHref)) {
+ $tradHref = $base . '/' . ltrim($tradHref, '/');
+ }
+ $links[] = '<link rel="alternate" hreflang="' . htmlspecialchars(strtolower($trad['lang']), ENT_QUOTES, 'UTF-8') . '" href="' . htmlspecialchars($tradHref, ENT_QUOTES, 'UTF-8') . '">';
}
}
- $headerlib->add_rawhtml(implode("\n", $links) . "\n");
+ if (! empty($links)) {
+ $headerlib->add_rawhtml(implode("\n", $links) . "\n");
+ }
}
if ($prefs['feature_machine_translation'] == 'y' && $prefs['lang_machine_translate_wiki'] == 'y' && ! empty($this->info['lang'])) {
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/83196a134876f4538f4b3663d4e2f2c33fe9c49e
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/83196a134876f4538f4b3663d4e2f2c33fe9c49e
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs