Adding custom code to the <head> section

Rate this topic: Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.1.00 out of 6 based on 1 vote(s)
GK User
Tue Mar 25, 2014 5:19 pm
Reply with quote
Report this post
Hi ,

I tried to add my custom code
Code: Select all
<?php $this->setGenerator('my name'); ?>
into the <head> section in templates/templatename/layouts/default.php

but I got an error: Fatal error: Call to undefined method GKTemplate::setTitle() in

I tried to add the code into templates/templatename/layouts/blocks/head.php

but again I got the same error.

Can you help me where I can add this code ?

Thank you in advance
User avatar
Fresh Boarder

GK User
Tue Mar 25, 2014 10:19 pm
Reply with quote
Report this post
Hi,
you are my local hero. you broke and you admit it, most of users are hiding this and trying to convince us that it's our fault.

Why you want to add this code?
If you want to hide metatag with "Made by Joomla" better use plugin which do it much better. For example ByeByeGenerator
User avatar
Platinum Boarder

GK User
Wed Mar 26, 2014 1:47 pm
Reply with quote
Report this post
Pawel F wrote:Hi,
you are my local hero. you broke and you admit it, most of users are hiding this and trying to convince us that it's our fault.

Why you want to add this code?
If you want to hide metatag with "Made by Joomla" better use plugin which do it much better. For example ByeByeGenerator


Hi :) of course I will admit it :) if something is broken because of me

Actually I don't want to use plugins ( I prefer such small things to add directly into the code) - more plugins , less speed :)

And also I want to add another modification to the template - for example to make the Home page showing only the Site name (not Home - Site Name, or Site Name - Home)
I am gonna use this example code
Code: Select all
<?php
  $menuItemId = JRequest::getInt('Itemid');
  if ($menuItemId == 101) $this->setTitle('Site Name');
?>


But it must be added in the template head section too. That's why I'm searching the proper way to add it.

Can you tell me in which file I must add it ?
User avatar
Fresh Boarder

GK User
Wed Mar 26, 2014 9:09 pm
Reply with quote
Report this post
Why?
You don't have to add php code to use site name or what ever on home page - please use default Joomla features first. In Menu Manager in Item settings you will find all!
User avatar
Platinum Boarder

GK User
Thu Mar 27, 2014 9:24 am
Reply with quote
Report this post
Pawel F wrote:Why?
You don't have to add php code to use site name or what ever on home page - please use default Joomla features first. In Menu Manager in Item settings you will find all!


OK here is why
About the site name on the home page. I set in the settings, to add the site name , after my page titles. Now I have for ex. Contacts - Site name - this is good.
But on my Home page I have Home - Site name. I don't want to have Home word., but only the Site Name (on my home page). As you suggest to put in Menu Manager-> Browser Page Title - and now I have Site name - Site name. That's why I want to put the code directly into the template and to avoid all this things.
The same is with the Joomla generator.

So please, can you tell me where I must put my codes, to be applied to the <head> section of the template ?

Thank you in advance
User avatar
Fresh Boarder

GK User
Thu Mar 27, 2014 11:15 am
Reply with quote
Report this post
Ok Pawel, as you didn't tell me how to achieve what I want , I fount it by myself

And as always I will put here the resolve

If you want to add a custom code to the <head> section of you site, add it into your folder: templates/templatename/layouts/default.php

For example if you want to remove Joomla generator add this:
Code: Select all
<?php JFactory::getDocument()->setGenerator('leave empty or give it a name'); ?>


Regards
User avatar
Fresh Boarder

GK User
Thu Mar 27, 2014 5:15 pm
Reply with quote
Report this post
First, I'm talking you again, you don't have to customize php code to add this site name. Menu Manager: Menu Items.
PageTitle.png


Second, Sorry but we don't help in PHP customizations, this forum is not a template workshop.
User avatar
Platinum Boarder

GK User
Thu Mar 27, 2014 8:27 pm
Reply with quote
Report this post
Pawel F wrote:First, I'm talking you again, you don't have to customize php code to add this site name. Menu Manager: Menu Items.
PageTitle.png


Second, Sorry but we don't help in PHP customizations, this forum is not a template workshop.



Hi again,

I understood you very well, but as I wrote I was activating the option in Joomla t oadd the Site Name after the page title. And if I use the option you show me, I am getting in my browser -> Browser Page Title - Site Name.
But in home page, I wanted to have only the Site Name , not the Page+Site name
Ans if in the Browser Page Title I write my site name, then I got Site Name - Site Name

Never mind , as I already post, I manage to fix my problem and posted it here

Thanks
User avatar
Fresh Boarder

GK User
Thu Mar 27, 2014 8:53 pm
Reply with quote
Report this post
I tried on J2.5
and I had (still have) only
<title>MyHomePage</title>
on Home page.
ok, I know why ....
In Global configuration I have:
Include Site Name in Page Titles : None
That's why.

Sorry ;) my fault.
You have to check other solutions...
or customize code... but remember <title> part is from joomla not from template.
User avatar
Platinum Boarder


cron