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

How add rel=canonical tag in questions page and hot page and Unanswered page ?

Q2A version: 1.7.4

2 Answers

+1 vote
selected by
Best answer

A better check to do instead of comparing $pagetitle from the other answer, is to compare to the $this->template property. The page title is more dynamic so comparing that is more brittle (e.g. if you use a different language). $this->template will be 'questions' or 'hot' or 'unanswered' in your 3 situations specified.

And it's also better to specify the URL in the property $this->content['canonical'] and let the theme do the rest of the work (the canonical will be output in the head_links method).

Example code to go in the initialize function in your custom theme or layer override:

if ($this->template === 'questions') {
    $this->content['canonical'] = qa_path_html('questions');
if ($this->template === 'hot') {
    $this->content['canonical'] = qa_path_html('hot');
if ($this->template === 'unanswered') {
    $this->content['canonical'] = qa_path_html('unanswered');

reshown by
Im using cleanstrap theme? where  exactly to add this code
+1 vote

OPEN qa-include/qa-theme-base.php

Add the following code into public function head_metas(). For canonical URL replace your own one.

if ($pagetitle == "Recent questions" || $pagetitle == "Hot questions" || $pagetitle == "Recent questions without answers")

$this->output('<link rel="canonical" href="http://www.e-dostluk.com"/>');