Created
August 26, 2018 09:37
-
-
Save mrkdevelopment/ab9d8d8d031e74aafc6760237dae22dd to your computer and use it in GitHub Desktop.
Learndash Yoast Breadcrumbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can read how this code works on my website here - https://www.diviframework.com/topic/breadcrumb-learndash-snippet/