Social Media Share Buttons under Each Question Response
I recently updated to v1.8.8, and I’m seeing a problem I hadn’t noticed before. When taking a quiz, the social media share buttons are showing up under each multiple choice response. Before, the buttons appeared at the end of the results, but now they’re within the quiz.
Is there some way to shut this off? I actually don’t want the share buttons to show up in the quiz anywhere, even on the results page.
I’m using the “Add to Any” plugin for the social media share buttons. I temporarily changed the setting so that it only displays on pages (not posts), and that fixed the problem with the quizzes, but I do want to have the buttons on posts, so I turned the post option back on so you could see the problem.
BTW I just tried this on another site that I manage. The social media buttons did NOT show up using HD Quiz v1.8.7. But when I updated to v1.8.8, they did show up. This site uses the same “Add To Any” plugin. Even though the “show on posts” option was turned on, the buttons did not appear until I updated to HD Quiz v1.8.8.
the reason this is happening is twofold.
First, plugins like the Add to Any plugin “cheat” by using WordPress’
the_content filter to add their own content to it. This is how they automatically add the social share buttons to the end of your pages.
The problem is that these plugins add the content every time
the_content runs on a page.
The latest version of HD Quiz now runs each answer through
the_content filter so that answers can contain things like shortcodes for KaTex or anything else. On its own, this isn’t an issue, as this is a 100% intended use case. But it causes plugins like the Add to Any plugin to repeat its own content multiple times.
So how to fix?
First, I’ll be releasing an update later today that should fix this for you automatically by adding a new setting in the HD Quiz → About / Options page to enable or disable the filter on answers. Since I assume you are not using shortcodes inside of answers, this should work well for you.
HOWEVER, the best method is to make an update to your site so that not only will this not be an issue with HD Quiz, but it will also fix any other plugin or theme that needs to use
the_content filter. This method will only be doable if you are comfortable editing your theme.
NOTE: I am writing this not just for your benefit, but also for anyone else who ever comes across a similar issue.
Plugins like AddToAny have options to automatically add their content to your posts and page. They do this by just appending their content whenever
the_content is run. It is this automatic feature that is the problem, since that filter can run multiple times on a page. This is why most plugins like this also have a way to manually choose where to add the content, thus avoiding the issue altogether.
For example, AddToAny has a shortcode
[addtoany] that allows you to either manually add to each page or post (yuck, that sounds time-consuming!), or to edit your theme template files to run the shortcodes there.
The way to do this depends on your theme, but generally speaking, here are the steps.
To add to posts, edit your theme and look for
single.php this is the main template file that handles posts. Pages would be
page.php. This can get complicated based on your theme since some developers also use template-parts or nest multiple files etc, but these files are, at the very least, the first place to look.
Now you want to look for something similar to
the_content (it might also be
get_the_content). Now decide if you want your share buttons below, or above the content (or both!), and add the following code
(NOTE: do not add thephp` tags if already inside a PHP function. Always back up a file before editing in case you make a mistake)
And now you can edit the plugin settings to disable automatically adding the content and that’s it! The share buttons will only ever load once now.
Awesome! Thanks so much for your quick response and detailed answer.
I just updated from v 1.8.8 to 1.8.9, but for some reason I don’t see anything new on the “About/Options” page. Here’s what I see:
It looks like the same four switches under “Other Options”, and I don’t see any entries anywhere about disabling the filter.
I tried clearing my cache, de-activating/activating HD Quiz, and rebooting my computer. But I still don’t see the new control. What am I doing wrong?
You said that each ANSWER is run through “the_content” filter so that we can use shortcodes. Is this the case for everything displayed in a quiz (such as the Question, pass/fail text boxes, etc, etc) or is this only for the multiple choice ANSWERS? I’m wondering if I can now use plugin shortcodes within my questions or other text? I don’t think I’m currently doing that, but it might be useful if it is an option for me.
Of course, until I do something about AddToAny, I’ll keep the filter “disabled on answers” using the new feature (thanks!!!!!!)
Thanks again for the quick help and answer; that’s what makes this plugin so great!
I actually decided on a more automated method instead of using a new options/setting, so no action is required on your end 🙂
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 may still end up adding it as an actual setting in the future depending on user feedback, but it will be opt-in instead of opt-out.
You can use shortcodes inside the quiz pass and quiz fail text – and have been able to for a long time (a few years now at least!). These fields actually have the same issue that you had with the answers and the social share plugin adding extra content, but I avoid this problem by simply hiding that extra content using CSS. A “good enough” solution when we only need to hide it twice, but a terrible solution if we need to hide potentially hundreds of instances with the answers.
The “automated method” does the trick! The share buttons aren’t showing up with each multiple choice answer like it was before, even when I enable them to appear on posts.
But I did notice that they show up under the “Text that appears if the user got the answer wrong” (or right). Here’s how one question comes up after the wrong answer was selected:
Maybe I’ll eventually find a setting in AddToAny that might help. But I can live with this; having it on every multiple choice answer was pretty distracting, but the latest version fixes that.
I’ll have to play around with some of the other text boxes- I’ve never tried to use any shortcodes there.
Thanks again for all you do to keep improving this plugin.
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.