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

Hi there. I'm using Q2A with great pleasure, but there is one question from me. How to add custom text to only main page title?

I'm using Q2A with no site name for SEO purposes and everything is great except the main page. It has no title. I mean www.site.com main page title is empty, if you get look to the page source it looks:  <title></title>. How can i add custom text to only main page, without disrupting other pages tiitle? Thank you!

Q2A version: 1.5.4

4 Answers

+3 votes
by

You can specify title for home page using $this->template == 'qa'

There are two ways to do. In your theme file add this function

function head_title()

{

$pagetitle=strlen($this->request) ? strip_tags(@$this->content['title']) : '';
$headtitle=(($this->template == 'qa') ? 'YOUR CUSTOM TITLE HERE' : (strlen($pagetitle) ? ($pagetitle.' - ') : '').$this->content['site_title']);
 
$this->output('<TITLE>'.$headtitle.'</TITLE>');
}
 
Change YOUR CUSTOM TITLE HERE with whatever you want. This will display your custom title on Home page only

 

+1 vote
by

My way:

add in qa-theme-basephp

in function head_title() {

add these lines

$variable=$_SERVER['REQUEST_URI'];

if ($variable=='/') {$this->output('<TITLE> the title </TITLE>');

 

else
{ $this->output('  <TITLE>'.$headtitle.'</TITLE>'); }

 

}

+1 vote
by

In my case.

function head_title()
{
  $pagetitle=strlen($this->request) ? strip_tags(@$this->content['title']) : '';
  $headtitle=((qa_request() == '') ? 'YOUR CUSTOM TITLE HERE' : (strlen($pagetitle) ? ($pagetitle.' - ') : '').$this->content['site_title']);
  $this->output('<TITLE>'.$headtitle.'</TITLE>');
}
Note: admin->Layout->Custom content in home page instead of Q&A
by
May be I am wrong but I have checked and this doesn't work. I believe qa_request() needs a value to compare. When I gave value to 'qa' than it works. This means it doesn't make any difference. Please check and give your feedback. If it works than this can be better approach.
by
edited by
Thanks Jatin. It moved in my environment correctly. Are there any differences in the environment of me and you? Moreover, I am also using PATH MAP of qa-config.php with the alternative homepage at my site.

admin -> layout -> Custom content in home page instead of Q&A : ON
  +
    $QA_CONST_PATH_MAP=array(
        'qa' => 'topics',
        'questions' => 'consultations',
    );
by
Exactly! I am using the same setup. In fact fro custom page I am testing with one step further by defining Custom PHP page as a home page and not the Custom content in home page. But I believe both covered under Custom in the system and qa_request() should work for both if it does..
–1 vote
by

It's very simple :)).....  

Suppose my Q&A site Name is ABC. Then there will be only one page in my entire site whose title will say ABC.

So here is the code: 

 

function head_title()
{
$pagetitle=strlen($this->request) ? strip_tags(@$this->content['title']) : '';
$headtitle=(strlen($pagetitle) ? ($pagetitle.' - ') : '').$this->content['site_title'];
 
if (($headtitle == "ABC"))
 {
  $this->output('<TITLE>NEW ABC TITLE</TITLE>');
 }
else
 {
  $this->output('<TITLE>'.$headtitle.'</TITLE>');
 }
 
}
by
Which file has to be edited. I mean to say where I have to use the code.
...