PDA

View Full Version : Custom browser tab names


Dinocanid
01-20-2017, 09:50 PM
It was bothering me for the longest time how the tab name in your browser was always the name of your site, no matter what page you're on. Imagine members opening multiple tabs for different pages on your site and they can't tell which is which! I went ahead and fixed that.

-Step 1-
Go to public_html/templates/(Whatever theme you're using)/header.tpl. See the lines that look like this?:
<title>{$browser_title}</title>
Delete them. In case you have two of these lines, delete them both. If you feel uncomfortable about deleting them (maybe you want it for later?), just comment them out like this:
<! --<title>{$browser_title}</title> -->

-Step 2-
Now you can rename the tabs! For example, let's rename the tab of the inventory page. Go to inventoryview.php, find these lines:
public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle($mysidia->lang->inventory);

And change it to this:
public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->add(new Comment("<title>Inventory</title>"));
$document->setTitle($mysidia->lang->inventory);

-End-
You're done! The downside is that you'll have to do this for all of your pages, or else the tab name will just be the full URL. This works for pages made in the adminCP too! Just go to edit your custom page and add this before the rest of your content:
<title>Tab Title</title>

-Why edit the code?-
I found that if you attempt to use the html title tags without editing the header.tpl, then they won't work because they're being overridden. It is also important to note that this doesn't conflict with:
$document->setTitle("Title");
Because that is for the title on the actual page itself, not the browser tab.