Title: adding Play again Button
Last modified: September 2, 2019

---

# adding Play again Button

 *  Resolved [mubasher99](https://wordpress.org/support/users/mubasher99/)
 * (@mubasher99)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/adding-play-again-button/)
 * Hi there love your plugin..!
    I have 2 questions: **1.** is there any way that
   i may include “Play Again” button in the result section after the quiz is submitted?**
   2. **How can i change the formatting of the result page. As it shows result as:
   16/20-80% i want to show it like: Total correct answers= **16** Total Wrong Answers
   = **4** Total percentage= **80%**

Viewing 1 replies (of 1 total)

 *  Plugin Author [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * (@harmonic_design)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/adding-play-again-button/#post-11894408)
 * Hi mubasher99,
    the easiest way to have a “play again” button is to include a
   link (or button shortcode if your theme uses one) in the results field that simply
   links back to the quiz page. The page will refresh and the user can retake the
   quiz.
 * As for changing the formatting of the results… that’s a bit harder, but still
   doable. There are two ways to do this. The first is to edit `includes/js/hdq_script.
   js` and taking a look at line `147 hdq_calculate_total()`, **but I’d recommend
   waiting a few days since** I’ll be releasing the new version of HD Quiz then.
 * The new version includes a hook on quiz completion allowing you to add your own
   functions once the quiz has been submitted. Using this, you’ll be able to add
   the following code to your theme’s `functions.php` file.
 * The following is just an example but once the new version is up, this should 
   work for you.
 *     ```
       function hdq_submit($quizOptions){
       	$quizOptions->hdq_submit = "hdq_custom_submit";
       	return $quizOptions;
       }
       add_action( 'hdq_submit', 'hdq_submit' );
       // the above tells HD Quiz to look for a function called hdq_custom_submit and to fire it off. It will then also try and send data to admin-ajax, but we won't be using that part.
   
       function hdq_before_test($quizID){
       	?>
           <script>
       	function hdq_custom_submit(){
       		let data = {};
       		// hdq_score is array of score (score/total questions)
                       let c = hdq_score[0];
                       let t = hdq_score[1];
                       let p = (parseFloat(c) / parseFloat(t)) * 100;
                       p = p.toFixed(2);
                       let d = '<p>Total correct answers= <strong>'+c+'</strong><br/>
       Total Wrong Answers= <strong>'+t+'</strong><br/>
       Total percentage= <strong>'+p+'</strong><br/>%</p>';
                       jQuery(".hdq_results_inner .hdq_result").html(d);
       		return JSON.stringify(data); // expects a json string to be returned
       	}
           </script>
       <?php
       }
       add_action( 'hdq_before', 'hdq_before_test' );
       // the above allows us to add any code to HD Quiz before the quiz. This can be any HTML, PHP, JS, whatever! We are using it to add a custom JS function
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘adding Play again Button’ is closed to new replies.

 * ![](https://ps.w.org/hd-quiz/assets/icon-256X256.gif?rev=2936040)
 * [HD Quiz](https://wordpress.org/plugins/hd-quiz/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/hd-quiz/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/hd-quiz/)
 * [Active Topics](https://wordpress.org/support/plugin/hd-quiz/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/hd-quiz/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/hd-quiz/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Harmonic Design](https://wordpress.org/support/users/harmonic_design/)
 * Last activity: [6 years, 9 months ago](https://wordpress.org/support/topic/adding-play-again-button/#post-11894408)
 * Status: resolved