13 | Posts |
We would like to alter the TITLE tag (as displayed in the browser's tab or title bar). The options seem to be:
1. The worst solution would be to manually modify the function GetHead_TKD() at Line 2053 in "include/tool/gpOutput.php". Here, one can easily change the separator from ' - ' to ' | ', swap the order of $config['title'] with the page title, or omit the $config['title'] entirely. However, any changes here must be re-applied when Typesetter is upgraded, which causes maintenance issues. We would prefer to avoid this.
2. Another possible solution may be to create a plugin which hooks to gpOutput::GetHead that would allow the TITLE tag to be overridden. Is this possible? Which variable would the plugin need to modify in order to intercept and alter the TITLE before it is rendered?
3. Another possible solution may be to provide a core configuration setting that could be used to construct the TITLE. For example, if(isset($config['customtitle'])), then a TITLE template could be used within GetHead_TKD() to construct the string, e.g. "SITE_TITLE | PAGE_TITLE", with the variables replaced accordingly.
4. Finally, our preference is that this could be done within the template. However, this seems to be impossible with a call to ob_start() before gpOutput::GetHead inside the template, because it appears to only insert a placeholder where the actual HEAD content will later appear. In other words, the actual HEAD data does not seem to be accessible from within the template for modification.
Changing the title style is a pretty trivial change, but the concern is that any modifications to the code will be lost upon upgrading. Any ideas?
263 | Posts |
20.8K | Downloads |
1 | Themes |
8 | Plugins |
1.5K | Posts |
62.6K | Downloads |
16 | Plugins |
This would be a modified MetaTitle function (/include/tool/Output.php, from line 1321) that calls a new plugin filter hook "MetaTitle"
/** * Add the <title> tag to the page * return the value * */ public static function MetaTitle(){ global $page, $config; $meta_title = ''; $page_title = ''; if( !empty($page->TitleInfo['browser_title']) ){ $page_title = $page->TitleInfo['browser_title']; }elseif( !empty($page->label) ){ $page_title = strip_tags($page->label); }elseif( isset($page->title) ){ $page_title = \gp\tool::GetBrowserTitle($page->title); } $meta_title .= $page_title; if( !empty($page_title) && !empty($config['title']) ){ $meta_title .= ' - '; } $meta_title .= $config['title']; $meta_title = \gp\tool\Plugins::Filter('MetaTitle', array($meta_title) ); // msg("MetaTitle after Plugin Filter: " . pre($meta_title)); echo "\n" . '<title>' . $meta_title . '</title>'; return $page_title; }
With this new filter, a plugin or a theme will be able to modify the browser title.
Replace the function and see/install this small proof-of-concept plugin…
Installation:
Unpack the ZIP into your /addons directory and install it via
Admin Toolbox → Plugins → Manage → Available → Install
edit: I made a pull request on github. If Josh is willing to add the new hook, CMS updates will be safe.
13 | Posts |
A new release for Typesetter is in the works with a lot of improvements including the ... Read More
Typesetter 5.1Typesetter 5.1 is now available for download. 5.1 includes bug fixes, UI/UX improvements, ... Read More
More NewsFind out more about our Provider Spotlight
What CMS: Find out what CMS a site is using.
Who Hosts This: Find out who is hosting any web site
WordPress Theme Detect: Find out which theme a WordPress site is using