Skip to content

Instantly share code, notes, and snippets.

@stompweb
Created March 4, 2017 10:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stompweb/3353832f82cedb96b2eb5a8d2c9503ab to your computer and use it in GitHub Desktop.
Save stompweb/3353832f82cedb96b2eb5a8d2c9503ab to your computer and use it in GitHub Desktop.
Yoast breadcrumbs for LearnDash
<?php
function stomp_filter_learndash_yoast_breadcrumbs( $links ) {
$course_label = 'Courses';
$labels = get_option( 'learndash_custom_label_settings' );
if ( ! empty( $labels['courses'] ) ) {
$course_label = sanitize_text_field( $labels['courses'] );
}
if ( is_singular( 'sfwd-lessons' ) ) {
$breadcrumb[] = array(
'url' => get_post_type_archive_link( 'sfwd-courses' ),
'text' => $course_label,
);
$course_id = learndash_get_course_id();
$breadcrumb[] = array(
'url' => get_permalink( $course_id ),
'text' => get_the_title( $course_id ),
);
array_splice( $links, 1, 0, $breadcrumb );
}
if ( is_singular( 'sfwd-quiz' ) || is_singular( 'sfwd-topic' ) ) {
$breadcrumb[] = array(
'url' => get_post_type_archive_link( 'sfwd-courses' ),
'text' => 'Courses',
);
$course_id = learndash_get_course_id();
$breadcrumb[] = array(
'url' => get_permalink( $course_id ),
'text' => get_the_title( $course_id ),
);
$lesson_id = learndash_get_lesson_id();
$breadcrumb[] = array(
'url' => get_permalink( $lesson_id ),
'text' => get_the_title( $lesson_id ),
);
if ( is_singular( 'sfwd-quiz' ) ) {
array_splice( $links, 1, 1, $breadcrumb );
} else {
array_splice( $links, 1, 0, $breadcrumb );
}
}
return $links;
}
add_filter( 'wpseo_breadcrumb_links', 'stomp_filter_learndash_yoast_breadcrumbs' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment