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

2 Answers

+1 vote

1. Use CSS pseudo elements

One simple way of doing this, would be by simply adding a question mark with the use of pseudo elements in CSS. More specifically with  ::after .

.qa-main-heading h1 span:after {
    content: "?";

2. PHP Regex 

But adding a question mark like the example above could result in questions with double question marks. If the user also writes them in their questions -  "Why is the sky blue??" 

So you could remove the question marks directly on PHP by adding the customized two functions below, on your  qa-theme.php  file.

public function title()


    $q_view = @$this->content['q_view'];

    $q_view_title = preg_replace('/[?]/', '', $this->content['title']);

    // link title where appropriate

    $url = isset($q_view['url']) ? $q_view['url'] : false;

    if (isset($this->content['title'])) {


            $url ? '<a href="' . $url . '">' : '',


            $url ? '?</a>' : ''



    // add closed note in title

    if (!empty($q_view['closed']['state']))

        $this->output(' [' . $q_view['closed']['state'] . ']');


public function q_item_title($q_item)


    $q_title_custom = preg_replace('/[?]/', '', $q_item['title']);


        '<div class="qa-q-item-title">',

        '<a href="' . $q_item['url'] . '">' . $q_title_custom . '?</a>',

        // add closed note in title

        empty($q_item['closed']['state']) ? '' : ' [' . $q_item['closed']['state'] . ']',




Notice I created a preg_replace , but also added the question mark before the  </a>  tag closure.

3. Javascript - Cut the problem by the root

You could create a Javascript function to prevent users from adding question marks while writing the question title. This way you cut the problem by the root, avoiding users to write question marks on their questions and then you can use option 1 or option 2 with php to simply add the question mark at the end of the question text.

$('.qa-template-ask form[name="ask"] .qa-form-tall-text').keyup(function(e){
    $(this).val($(this).val().replace(/\?/g, ''));

You can find the uncostumized php code for those 2 functions on  qa-theme-base.php  at line 808 for the question title, and on line 1753 for question title on question lists. 
Copy them to your  qa-theme.php  and then add the question mark like the example on the PHP code I showed above.

+3 votes
There is a free plugin of mine for putting question mark at the end of question title automatically.

github download link