LearnDash: "Edit Course" Link in the Toolbar on Lessons
Adds an "Edit Course" link to the admin toolbar when you view a lesson, topic or quiz, so you can jump straight to the parent course's builder.
Opens WPIDE on
Code
if ( ! defined( 'LEARNDASH_VERSION' ) ) {
return;
}
add_action( 'admin_bar_menu', function ( $bar ) {
if ( ! is_singular( array( 'sfwd-lessons', 'sfwd-topic', 'sfwd-quiz' ) ) ) {
return;
}
$course_id = (int) learndash_get_course_id( get_queried_object_id() );
if ( ! $course_id || ! current_user_can( 'edit_post', $course_id ) ) {
return;
}
$bar->add_node( array(
'id' => 'wpide-ld-edit-course',
'title' => 'Edit Course',
'href' => get_edit_post_link( $course_id ),
) );
}, 90 );
Notes
Only shown to users who can edit the course.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.