Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
in Q2A Core by
I'd like to know how I can add meta tags automatically. I'd like the tags to be the keywords and the "More information for your question"  to be the description. Is that possible?

1 Answer

+2 votes
I'm sure this is a common question. The best way to do this is using an advanced HTML theme: http://www.question2answer.org/advanced.php#theme-advanced

Your theme's qa-theme.php should contain this:


    class qa_html_theme extends qa_html_theme_base
        function head_custom()
            if ($this->template=='question') {
                $this->output('<META NAME="description" CONTENT="'.strip_tags(@$this->content['q_view']['content']).'"/>');
                $this->output('<META NAME="keywords" CONTENT="'.strip_tags(implode(', ', @$this->content['q_view']['q_tags'])).'"/>');


What's happening here is that your theme is overriding the default head_custom() method (which does nothing) to output the meta tags, if this is a question page.

If you don't want to mess with advanced themes, you can also use the above function head_custom() to replace the one in qa-theme-base.php, but this will make it harder for you to upgrade to future versions of Q2A.

See also my comments here regarding whether meta tags are worthwhile:

It is a good option... Thanks!
But getting following error on editing any post..
Warning: implode() [function.implode]: Invalid arguments passed in /home/../public_html/qa-theme/Q2AStack/qa-theme.php on line 87

Any way to avoid this?
For your information, version 1.2 now takes care of these meta tags for you automatically.

As for the error, you can try putting an @ sign before word implode.
Then i can remove this extra coding, rt?
Description and Keywords will be generated based on question, rt?

Thank you.
Yes, that's right, once you upgrade to 1.2.