I am using a text-to-speech plugin and I need to insert a button before each question using a shortcode on unit based practice quizzes and quizzes. Is there a hook I can use to place this button before each question?
Hi...
There is only one hook in the question which executes after the question options.
But you need to show the button before question content, so you can use the wordpress"the_content" filter and check if the post type is question then show the button.
Example :
add_filter('the_content',function($content){ global $post; if($post->post_type == 'question'){ //Here output your button. } return $content;});
I tried implementing the code you provided in my functions.php file. However, when I implement the code, it breaks my website and results in a white page. Here is how I implemented the code:
Well you need to echo your shortcode like this:
add_filter('the_content',function($content){ global $post; if($post->post_type == 'question'){ echo do_shortcode('[readspeaker_listen_button]'); } return $content;});
The code is fine it will not give you any error, to check the code you can simply remove your shortcode and echo your name it will work fine.
I copied the code you provided into my functions.php file. Instead of the button appearing before each question, I just got a bunch of buttons appearing at the top of the page. I tried echoing my name to see if it was just the button, but my name appeared the same way. Here is a screenshot for reference: