Skip to content

Instantly share code, notes, and snippets.

@mrkdevelopment
Created August 26, 2018 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrkdevelopment/ab9d8d8d031e74aafc6760237dae22dd to your computer and use it in GitHub Desktop.
Save mrkdevelopment/ab9d8d8d031e74aafc6760237dae22dd to your computer and use it in GitHub Desktop.
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
Copy link
Author

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