How do I set the <head>'s <title> tag in MVC component's code? I know the page title (which would appear on top of the page) can be set in several ways but the <title> seems to be only settable from menu item properties. I need to set <title> without using menu items (from component code).
- Looks like a duplicate of joomla.stackexchange.com/search?q=setTitle+is%3Aquestion. If not please clarify.mickmackusa– mickmackusa ♦2020-05-06 21:16:48 +00:00Commented May 6, 2020 at 21:16
Add a comment |
1 Answer
You can use Joomla's setTitle() method, like so:
use Joomla\CMS\Factory; Factory::getDocument()->setTitle('My Custom Title'); - It seems to set the tile on the site but not the <title> tag contents in the <head> section of the page.ed22– ed222020-05-06 12:08:42 +00:00Commented May 6, 2020 at 12:08
- @ed22 - Working perfectly fine for me. The browser sets the page title based on the
<title>value, so I'm not sure how the tab shows the title but the<title>isn't updating.Lodder– Lodder2020-05-06 13:00:30 +00:00Commented May 6, 2020 at 13:00