Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Learndash Yoast Breadcrumbs
add_filter( 'wpseo_breadcrumb_links', 'wpse_100012_override_yoast_breadcrumb_trail' );
function wpse_100012_override_yoast_breadcrumb_trail( $links ) {
global $post;
if ( is_singular( 'sfwd-lessons' ) ) {
$course_id = learndash_get_course_id($id);
$course_title = get_the_title($course_id);
$breadcrumb[] = array(
'url' => get_post_type_archive_link( 'sfwd-courses' ),
'text' => 'Courses',
);
$breadcrumb[] = array(
'url' => get_permalink( $course_id ),
'text' => $course_title,
);
array_splice( $links, 1, -2, $breadcrumb );
}
if ( is_singular( 'sfwd-topic' ) ) {
$course_id = learndash_get_course_id($id);
$course_title = get_the_title($course_id);
$parent_lesson_id = learndash_get_setting( $post, 'lesson' );
$lesson_title = get_the_title($parent_lesson_id);
$breadcrumb[] = array(
'url' => get_post_type_archive_link( 'sfwd-courses' ),
'text' => 'Courses',
);
$breadcrumb[] = array(
'url' => get_permalink( $course_id ),
'text' => $course_title,
);
$breadcrumb[] = array(
'url' => get_permalink( $parent_lesson_id ),
'text' => $lesson_title,
);
array_splice( $links, 1, -2, $breadcrumb );
}
return $links;
}
@mrkdevelopment

This comment has been minimized.

Copy link
Owner Author

commented Aug 26, 2018

You can read how this code works on my website here - https://www.diviframework.com/topic/breadcrumb-learndash-snippet/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.