Skip to content

Commit

Permalink
[custom html headers] simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Feb 12, 2025
1 parent f6cf1ab commit b1aae0d
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions ext/custom_html_headers/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,24 @@ public function onInitExt(InitExtEvent $event): void
$config->set_default_string("sitename_in_title", "none");
}

# Load Analytics tracking code on page request
public function onPageRequest(PageRequestEvent $event): void
{
$this->handle_custom_html_headers();
$this->handle_modified_page_title();
}

private function handle_custom_html_headers(): void
{
global $config, $page;

$header = $config->get_string('custom_html_headers', '');
if ($header != '') {
$page->add_html_header(rawHTML($header));
}
}

private function handle_modified_page_title(): void
{
global $config, $page;

// get config values
// check sitename is not already in title (can occur on index & other pages)
$site_title = $config->get_string(SetupConfig::TITLE);
$sitename_in_title = $config->get_string("sitename_in_title");

// sitename is already in title (can occur on index & other pages)
if (str_contains($page->title, $site_title)) {
return;
}

if ($sitename_in_title == "prefix") {
$page->title = "$site_title - $page->title";
} elseif ($sitename_in_title == "suffix") {
$page->title = "$page->title - $site_title";
if (!str_contains($page->title, $site_title)) {
if ($sitename_in_title == "prefix") {
$page->title = "$site_title - $page->title";
} elseif ($sitename_in_title == "suffix") {
$page->title = "$page->title - $site_title";
}
}
}
}

0 comments on commit b1aae0d

Please sign in to comment.