Step #1: Enable “custom fields” support for Lessons and Topics
Add this PHP code snippet to enable WordPress custom fields:
add_action( 'init', 'lmscoder_custom_fields_support_learndash' );
function lmscoder_custom_fields_support_learndash() {
$post_types = [
'sfwd-lessons',
'sfwd-topic',
];
foreach ( $post_types as $post_type ) {
add_post_type_support( $post_type, 'custom-fields' );
}
}
Step #2: Confirm “custom fields” support
Check the “Custom Fields” checkbox in the Screen Options when editing a Lesson.
Step #3: Add duration_in_seconds key-value pairs
Add custom field entries with the key duration_in_seconds containing numeric values representing seconds (e.g., 500).
Step #4: Display the data
Helper function to get duration:
function lmscoder_get_duration( $post_id ) {
return get_post_meta( $post_id, 'duration_in_seconds', true );
}
Display via the_title filter:
add_filter( 'the_title', 'lmscoder_add_time_to_title', 10, 2 );
function lmscoder_add_time_to_title( $title, $id ) {
$formatted_time = lmscoder_get_duration( $id );
if ( $formatted_time AND ! is_admin() ) {
$title = $title . '<span class="course-step-duration">' . $formatted_time . '</span>';
}
return $title;
}
Style the time:
.course-step-duration {
display: none !important;
background: #db2020;
color: #fff;
font-size: 90%;
padding: 5px;
margin-left: 10px;
font-weight: bold;
display: inline-block;
line-height: 1;
position: relative;
top: -.1em;
}
.ld-course-navigation .course-step-duration,
.ld-item-list .course-step-duration {
display: inline-block !important;
}
Step #5: Format the time
function lmscoder_seconds_to_time( $seconds ) {
$seconds = intval( $seconds );
$hours = floor( $seconds / HOUR_IN_SECONDS );
$minutes = floor( ( $seconds / 60 ) % MINUTE_IN_SECONDS );
$seconds = floor( $seconds % MINUTE_IN_SECONDS );
$time = '';
if ( $hours >= 1 ) {
$time .= $hours . 'hr, ';
}
if ( $minutes >= 1 ) {
$time .= $minutes . 'min, ';
}
$time .= $seconds . 'sec';
return $time;
}
Update the helper function:
function lmscoder_get_duration( $post_id ) {
$seconds = get_post_meta( $post_id, 'duration_in_seconds', true );
if ( ! $seconds ) {
return false;
}
$formatted_time = lmscoder_seconds_to_time( $seconds );
return $formatted_time;
}
Step #6: Template override breadcrumbs
Copy wp-content/plugins/sfwd-lms/themes/ld30/templates/modules/breadcrumbs.php to wp-content/uploads/learndash/templates/ld30/modules/breadcrumbs.php
Replace line 33:
<span><a href="<?php echo esc_url( $breadcrumbs[ $key ]['permalink'] ); ?>"><?php echo esc_html( wp_strip_all_tags( $breadcrumbs[ $key ]['title'] ) ); ?></a> </span>
With:
<span><a href="<?php echo esc_url( $breadcrumbs[ $key ]['permalink'] ); ?>"><?php echo wp_kses_post( $breadcrumbs[ $key ]['title'] ); ?></a> </span>
Scope Limitations
The tutorial explicitly does not cover: automated duration calculations, per-user reading speeds, video API integration, or summing lesson substeps.