Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+7 votes
4.3k views
in Q2A Core by
edited by

Hi Everyone, I have been searching all over the forum, but couldnt find any code to fixe this issue.

How to change HOMEPAGE TITLE only? Without adding the site title! (I speak about title not H1)

I set up 'TAGS' => '', so my homepage is the list of tags in qa.config.php - Then in qa.lang-main.php I change the translation of the page. That is the good h1 title, but it's add the website title after, so google cut my title in search results...

I would like : <title>My homepage title</title>

Right now : <title> My homepage title - My site title</title>

So in search result : <title> My homepage titl...</title>

by
It is currently working that way in the core. I mean, regardless of the page you have as the homepage, make it All Activity or Q&A, if the request is for the homepage then the site name is not added to the title. For the rest of the pages it gets added. Unless you're using a custom theme, of course. Try this with the classic theme and double check that it works as you expect.
by
edited by
hi Puppi, its not because of the theme, its because I set homepage as "Tags"... so its had the title of the website after, even in homepage... So I need something like if($this->template == 'tags') => 'no homepage title"

1 Answer

+3 votes
by
edited by
 
Best answer

Now I see the issue. I misunderstood the 'tags' part. I could reproduce this situation you're facing. So, try this:

1. Edit your qa-theme/<your-theme>/qa-theme.php file

2. Locate function head_title

3.1 If you can't find it then add this function to the file:

function head_title() {
    if ($this->template === 'tags') {
        $headtitle=strip_tags(@$this->content['title']);
    } else {
        $pagetitle=strlen($this->request) ? strip_tags(@$this->content['title']) : '';
        $headtitle=(strlen($pagetitle) ? ($pagetitle.' - ') : '').$this->content['site_title'];
    }
   $this->output('<title>'.$headtitle.'</title>');
}
 
3.2 If you found it then you're using a custom theme which requires a custom solution. Anyway, you can still try replacing that function with the one in 3.1 and see if it works
by
Just got an error with TAG alone, everything is fine but I try to add ' | '  but its create an error <b>Notice</b>:  Undefined variable: pagetitle.

if ($this->template === 'tag' ) {
        $headtitle=strip_tags(@$this->content['title']) .$pagetitle.' | ' .$this->content['site_title'];
         $this->output('<title>'.$headtitle.'</title>');
    }
by
Bear in mind that is not the code I've added to the answer. You're outputting the title inside the IF statement and also using the $pagetitle variable in the previous line which is not defined. As I mentioned in my previous comment, you just need to modify one line to apply the same logic to other templates apart from the 'tags' one. Just change this line:

if ($this->template === 'tags') {

With this line (including any other templates you need):

if ($this->template === 'tags' || $this->template === 'activity' || $this->template === 'tag') {

Btw, if you end up having too many templates the previous line is equivalent to this less wordy alternative:

if (in_array($this->template, array('tags', 'activity', 'tag'))) {
by
Ok. I'm not 100% sure what title you want to display in the 'tag' page but I guess it is similar to the ELSE statement there. I think the result you should be getting is your expected result but you're just getting the notice. Just remove the variable and one dot around it (only for the $headtitle in the 'tag' section and NOT for the $headtitle in the ELSE statment in your code above):

$headtitle=strip_tags(@$this->content['title']) .' | ' .$this->content['site_title'];
by
edited by
Thanks a million man! everything works fine now!
...