Multiple Choice Question Answers Duplicating
When creating a multiple choice question with monetary answers such as £150.00, £250.00, £350.00 and £450.00, the first answer is being displayed for all answers – in this case, it’s displaying £150.00 for all answers.
Hi Darren,
this is certainly a weird one.
Firstly, I can think of no reason for this to happen. There’s nothing in the way that HD Quiz prints answers that could cause this behaviour. I was also unable to replicate the issue on my end.
However, taking a look at your quiz I can see that this is 100% an issue for you, and looking at the code of the rendered quiz…
What is going on here? I am so confused haha.
HD Quiz actually prints the answer three times on the page. The first is part of the title attribute so that the answer text appears on hover, the second is part of an aria label to help screen readers announce and select the answer, and the third is the visible answer that we normally see.
As you can see from your code, the answer is being correctly printed for each question for both the title and aria labels, but ONLY repeats for the actual visible.
This means that HD Quiz IS 100% able to correctly get and print the answers, but that for some reason, something on your site is rewriting the answers.
How to fix?
Ultimately, it’s best to track and find out what on your site it is that might rewrite content – especially anything involving currency.
I see that you are using WP Rocket for page caching. Try clearing your cache (or better yet, temporarily disable it) to see if this fixes the issue. Page cache plugins need to rewrite pages, so maybe WP Rocket is doing something weird.
I also see you are using some eCommmerce plugin “ibtana” – perhaps that plugin is modifying your content somehow to update/replace references to £
.
Something you can try is to edit that question, and instead of using £
, use the HTML character code £
. This might trick whatever system is modifying the page into ignoring this.
If the above doesn’t work, then this next one almost certainly will.
Edit the question and remove the £
and replace with <span class = "hd_pound"></span>
. This will add a custom span to the start of those answers.
Now since you are using the Styler addon(:D), we can do something cool. Go to the styler settings and enter the following in the advanced CSS section. .hd_pound:before { content: "£"; }
Since we aren’t printing the £ as part of the page and are instead using a clever way to add it with CSS, whatever system is modifying your content will almost certainly bypass this.
At the end of the day though, in order to track down what is actually causing this weird behaviour, you will need to do the WordPress Debug Steps
Hope this helps!
Hi,
I’ve tried all of the suggested fixes above and I’m still not getting this to work.
However, it doesn’t appear to be related to the ‘£’ sign as I’ve removed that and the issue is still present.
Any further thoughts?
Hi,
It’s also inconsistent with number answers and it doesn’t just apply to numbers. I’ve now found instances with alpha. I’ve uploaded some images.
Thanks
You have two options here.
Find out what is modifying your content
Something on your site (theme, plugin) is changing the content. Based on your recent replies, it looks like it is doing something that involves “symbols” – non “abcd…” characters. Read the WP Debug steps to see how you can track down which plugin (or possibly your theme) is doing these rewrites.
Modify HD Quiz
At this point, the only thing I am confident about is that A) something on your site is modifying your content, and B) the most likely way this is happening is through WordPress’ the_content
filter.
If you are unable, or unwilling, to do the WP Debug steps to find out what is causing this behaviour, then you can do the following edit to HD Quiz.
Edit ./hd-quiz/include/templates/default.php
and around line 24 you will see echo apply_filters('the_content', $answers[$i]["answer"]);
Replace that with echo $answers[$i]["answer"];
This will stop HD Quiz from passing the answers through WordPress’ the_content
filter. Assuming I’m right about whatever the thing is that is modifying your content is using that filter, this should fix the problem for you.
The only downsides are that A) You will not be able to use certain HTML tags or shortcodes in your answers, B) you will need to remember to make this small change each time you update HD Quiz as updates will overrite your custom change.
Thanks. I will carry out some more tests on my staging site to try and ascertain the cause.
In the meantime, I need to quizzes to work as expected.
How to apply the fix you suggest by bypassing the_content filter?
Apply the edit I wrote to ./wp-content/plugins/hd-quiz/includes/templates/default.php
. The best way to make this edit is up to you. You can use the plugin-editor built into WordPress (plugins -> plugin file editor), FTP, cPanel file manger, etc.
Here is a screenshot of how it looks with WordPress’ plugin editor
Hi Darren,
I don’t know if you still need help with this, but I just wanted to let you know that I’ll be releasing a minor update later today to add a new setting to the About / Options page that will enable or disable (it will be disabled by default) the_content
filter for answers. This should fix the issue for you
Hi Dylan,
I’ve not got round to carry out further tests yet but that’s great. Thank you.
Hi Dylan,
The plugin updated to version 1.8.9 overnight. I can’t see any relevant setting under About / Options or does that update not include the option yet?
Thanks
It’s actually not needed. I decided to go a different direction and try to automate it (btw, looking at your site, it looks like the update worked!)
The logic is pretty simple. Before printing an answer, I check to see if the answer contains a [
and a ]
. If it does, I assume that the answer contains a shortcode and run it through the the_content
filter. If it doesn’t, I just print the answer as normal.
I might still need to add an option to a future version depending on user feedback (maybe users want it to always go through the filter no matter what), but it will be opt-in, not opt-out, so you should be good to go!
Respond to thread
This thread has been closed / marked as resolved.
You can reply to this thread, but it might be better to start a new thread if you need help.
You can also upload images to imgur and paste the links here. Just make sure that your images don't include any sensitive information.
Submit