Stop lesson to quiz redirect

In certain WordPress setups, Sensei automatically redirects the lesson page to its quiz. This snippet helps you to stop that:

add_action('template_redirect', 'custom_remove_sensei_quiz_view');
function custom_remove_sensei_quiz_view(){
if( is_singular('quiz') ){
global $post;
//redirect back to the lesson page
$lesson_id = $post->post_parent;
//make sure this does not run again
$lesson_link = add_query_arg( 'sa', '1', get_permalink( $lesson_id ) );
wp_redirect( $lesson_link );
}
}
add_filter( 'wp_redirect', 'custom_sensei_stop_redirect_loop', 0, 2 );
function custom_sensei_stop_redirect_loop( $location, $status ){
$block_redirect = get_query_var( 'sa', '0' );
if( '1' == $block_redirect ){
$location = false;
}
return $location;
}

Please note that that is a developer level doc and all these customization snippets are for informational purposes only. Our support policy does not include assistance with customizations. We can not assist with modifying or debugging code from these snippets.