Question Hooks

Tagged: ,

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #118646
    pacworks
    Spectator
    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?
    #118718
    H.K. Latiyan
    Participant
    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; });
    #118799
    pacworks
    Spectator
    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:

    add_filter('the_content',function($content){

     global $post;

     if($post->post_type == 'question'){ do_shortcode('[readspeaker_listen_button]');

      }

     return $content;

    });

    I also tried this:

    $content = do_shortcode('[readspeaker_listen_button]');
    #118856
    H.K. Latiyan
    Participant
    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.
    #120062
    pacworks
    Spectator
    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: screenshot
    #120145
    H.K. Latiyan
    Participant
    Hi... Try adding the bellow code instead: add_filter('the_content',function($content){  global $post;  if($post->post_type == 'question'){     $return = do_shortcode('[readspeaker_listen_button]');     $return .= $content;     return $return;   }  return $content; });
    #120347
    pacworks
    Spectator
    That worked. Thanks!
Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Question Hooks’ is closed to new replies.