Code Snippets
PHP code snippets to customize Masteriyo LMS - change offline order status, sort courses, redirect after login or registration, resize course images, coupons.
All of the code snippets for modifying existing features can be found below. Check out this link if you do not know where to add custom code snippets to your site.
Change Default Order Status For Offline Payment
add_filter( 'masteriyo_offline_process_payment_order_status', function( $status ) {
return 'completed';
});
Want to know where and how to add code snippets? Check out this link
Change the Course Featured Label Pro
add_filter( 'masteriyo_pro_course_featured_text', function( $text ) {
return 'New Featured';
});
Want to know where and how to add code snippets? Check out this link
Sort the courses in the courses page alphabetically by course name.
add_filter( 'pre_get_posts', function ($q) {
// We only want to affect the main query.
if ( $q->is_main_query() && is_post_type_archive( 'mto-course' ) ) {
$q->set( 'orderby', 'title ID');
$q->set( 'order', 'ASC'); // ASC for A->Z or DESC for Z->A.;
}
});
Want to know where and how to add code snippets? Check out this link
Sort the courses in the courses page according to published date.
add_filter( 'pre_get_posts', function ($q) {
// We only want to affect the main query.
if ( $q->is_main_query() && is_post_type_archive( 'mto-course' ) ) {
$q->set( 'orderby', 'date ID');
$q->set( 'order', 'DESC'); // ASC for Oldest->Newest or DESC for Newest->Oldest
}
});
Want to know where and how to add code snippets? Check out this link
Sort the courses in the courses page according to modified date.
add_filter( 'pre_get_posts', function ($q) {
// We only want to affect the main query.
if ( $q->is_main_query() && is_post_type_archive( 'mto-course' ) ) {
$q->set( 'orderby', 'modified ID');
$q->set( 'order', 'DESC'); // ASC for Oldest->Newest or DESC for Newest->Oldest
}
});
Want to know where and how to add code snippets? Check out this link
Multiple Coupon Code Support Pro
add_filter('masteriyo_enable_multiple_coupon', function($bool, $coupon_code) {
return true;
});
Want to know where and how to add code snippets? Check out this link
Solution to Video Playback Fast-Forward or Rewind Function Not Working.
To ensure the security of your self-hosted videos, we apply various security measures. However, in certain cases, the hosting platform may clash with this security measure, making it impossible to forward or rewind the video by clicking on a specific time. In these scenarios, we suggest implementing the code snippet below to resolve the problem.
add_filter( 'masteriyo_self_hosted_lesson_video_url', function( $url, $lesson ) {
$url = wp_get_attachment_url( $lesson->get_video_source_id() );
return $url;
}, 10, 2);
Redirect to a Different Page After User/Instructor Registration
add_filter( 'masteriyo_registration_redirect_url', function( $url ) {
return get_permalink( 1 ); // Where 1 is the page/post id.
});
P.S. Currently, you cannot redirect to third-party websites. You can only redirect to the same website page.
Redirect to a Different Page After User/Instructor Is Logged In
add_filter( 'masteriyo_after_signin_redirect_url', function( $url ) {
return get_permalink( 1 ); // Where 1 is the page/post id.
});
Want to know where and how to add code snippets? Check out this link
Redirect to a Different Page After User/Instructor Is Logged Out
add_filter( 'masteriyo_redirect_logout_url', function($url) {
$url = 'http://www.google.com';
// replace http://www.google.com with your redirection link
return $url;
} );
Want to know where and how to add code snippets? Check out this link
Change Course Feature Image Size
add_filter( 'masteriyo_product_get_image', 'modified_img_size', 10, 4 );
function modified_img_size( $image, $course, $size, $attr ) {
if ( $course->get_image_id() ) {
$size = array('400','400'); // Your custom img size here.
$image = wp_get_attachment_image( $course->get_image_id(), $size, false, $attr );
}
return $image;
}
You can change the 400 and 400 image sizes according to your needs. Want to know where and how to add code snippets? Check out this link
Was this article helpful to you?
Give us Rating
Last edited on July 22, 2026.
Edit this page