'How to edit the Joomla template header?

Basically, I am just trying to slightly modify my Joomla template.

There is a line of code within the <head> of my template that is obviously grabbing things such as meta description, meta keywords and title tags.

Here is the code <jdoc:include type="head" />

I would like to know where this code is located since I would like my title tag above both my meta description and meta keywords.

Is this possible?



Solution 1:[1]

Try this,

Its not recommended editing core files.

You can find the meta and title section of the Joomla sites.

libraries\joomla\document\html\renderer\head.php

contains a function fetchHead()

Hope its helped...

Solution 2:[2]

You could copy the header.php to your template folder (name it head_renderer.php) and inside the index.php from your template reference the new header.php via:

require_once dirname(FILE) . DIRECTORY_SEPARATOR . 'head_renderer.php'; // our modifized renderer for the Joomla header

then you do not fully "edit the core files". However its a hack and not a template overwrite. But via this approach you can update joomla and do not need to check if your changed header.php is changed.

A better howto can be found here.

Solution 3:[3]

You can read the header values with...

$doc = JFactory::getDocument();
$head_data = $doc->getHeadData();

...then set new values, or update the existing values with code like...

$head_data["metaTags"]["name"]["twitter:title"] = $head_data["title"];

...then write it back with...

$doc->setHeadData($head_data);

See also https://stackoverflow.com/a/71410700/789137

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jobin
Solution 2 BastianW
Solution 3 AndyGaskell