[COURSEPRESS] custom link on course page

I need the breadcrumb to be on all the pages in the learning page, so users can go back the the course listing at any point or to a specific unit.

It’s not on the first page, when you click on a course so there is no way to go back to the course listing without going to the main menu.

  • Panos
    • SLS

    Hi Mikhail !

    I suppose you would like that link to be placed above the Course featured image. I have added a mu-plugin on your site, it’s this php file:

    yoursubdirectory/wp-content/mu-plugins/cp-link-to-courses.php

    with the following content:

    add_action( 'init', function(){

    if ( ! class_exists( 'CoursePress_Data_Shortcode_Course' ) ) {
    return;
    }

    remove_shortcode( 'course_media', array( CoursePress_Data_Shortcode_Course, 'course_media' ) );

    add_shortcode( 'course_media', function( $atts ){

    extract( shortcode_atts( array(
    'course_id' => CoursePress_Helper_Utility::the_course( true ),
    'class' => '',
    'height' => CoursePress_Core::get_setting( 'course/image_height' ),
    'list_page' => 'no',
    'priority' => '', // Gives priority to video (or image).
    'type' => '', // Default, video, image.
    'width' => CoursePress_Core::get_setting( 'course/image_width' ),
    'wrapper' => '',
    ), $atts, 'course_media' ) );

    $course_id = (int) $course_id;
    if ( empty( $course_id ) ) { return ''; }

    $type = sanitize_text_field( $type );
    $priority = sanitize_text_field( $priority );
    $list_page = cp_is_true( sanitize_html_class( $list_page ) );
    $class = sanitize_html_class( $class );
    $wrapper = sanitize_html_class( $wrapper );
    $height = sanitize_text_field( $height );
    $width = sanitize_text_field( $width );

    // We'll use pixel if none is set
    if ( ! empty( $width ) && (int) $width == $width ) {
    $width .= 'px';
    }
    if ( ! empty( $height ) && (int) $height == $height ) {
    $height .= 'px';
    }

    if ( ! $list_page ) {
    $type = empty( $type ) ? CoursePress_Core::get_setting( 'course/details_media_type', 'default' ) : $type;
    $priority = empty( $priority ) ? CoursePress_Core::get_setting( 'course/details_media_priority', 'video' ) : $priority;
    } else {
    $type = empty( $type ) ? CoursePress_Core::get_setting( 'course/listing_media_type', 'default' ) : $type;
    $priority = empty( $priority ) ? CoursePress_Core::get_setting( 'course/listing_media_priority', 'image' ) : $priority;
    }

    $priority = 'default' != $type ? false : $priority;

    // Saves some overhead by not loading the post again if we don't need to.
    $class = sanitize_html_class( $class );

    $course_video = CoursePress_Data_Course::get_setting( $course_id, 'featured_video' );
    $course_image = CoursePress_Data_Course::get_setting( $course_id, 'listing_image' );

    $content = '';

    if ( 'thumbnail' == $type ) {
    $type = 'image';
    $priority = 'image';
    $width = $height = '';
    }

    // If no wrapper and we're specifying a width and height, we need one, so will use div.
    if ( empty( $wrapper ) && ( ! empty( $width ) || ! empty( $height ) ) ) {
    $wrapper = 'div';
    }

    $wrapper_style = '';
    $wrapper_style .= ! empty( $width ) ? 'width:' . $width . ';' : '';
    $wrapper_style .= ! empty( $width ) ? 'height:' . $height . ';' : '';

    if ( is_singular( 'course' ) ) {
    $wrapper_style = '';
    }

    if ( ( ( 'default' == $type && 'video' == $priority ) || 'video' == $type || ( 'default' == $type && 'image' == $priority && empty( $course_image ) ) ) && ! empty( $course_video ) ) {

    $content = '<div class="video_player course-featured-media course-featured-media-' . $course_id . ' ' . $class . '">';

    $content .= ! empty( $wrapper ) ? '<' . $wrapper . ' style="' . $wrapper_style . '">' : '';

    $video_extension = pathinfo( $course_video, PATHINFO_EXTENSION );

    if ( ! empty( $video_extension ) ) {
    $attr = array(
    'src' => $course_video,
    );
    $content .= wp_video_shortcode( $attr );
    } else {
    $embed_args = array();

    // Add YouTube filter.
    if ( preg_match( '/youtube.com|youtu.be/', $course_video ) ) {
    add_filter( 'oembed_result', array(
    'CoursePress_Helper_Utility',
    'remove_related_videos',
    ), 10, 3 );
    }

    $content .= wp_oembed_get( $course_video, $embed_args );
    }

    $content .= ! empty( $wrapper ) ? '</' . $wrapper . '>' : '';
    $content .= '</div>';
    }

    if ( ( ( 'default' == $type && 'image' == $priority ) || 'image' == $type || ( 'default' == $type && 'video' == $priority && empty( $course_video ) ) ) && ! empty( $course_image ) ) {

    $content .= '<div class="course-thumbnail course-featured-media course-featured-media-' . $course_id . ' ' . $class . '">';
    $content .= ! empty( $wrapper ) ? '<' . $wrapper . ' style="' . $wrapper_style . '">' : '';

    $content .= '<img src="' . esc_url( $course_image ) . '" class="course-media-img"></img>';

    $content .= ! empty( $wrapper ) ? '</' . $wrapper . '>' : '';
    $content .= '</div>';
    }

    $courses_list_url = CoursePress_Core::get_slug( 'courses/', true );
    $back_to_list_link = "
    <div class="course-back-to-courses-link">
    <a href="{$courses_list_url}"> Back to courses list</a>
    </div>
    ";

    return $back_to_list_link . $content;

    } );

    }, 99 );

    If you would like to edit the link text, that part is at the bottom of the snippet at line 126.

    In case you would like to style it, you can use the .course-back-to-courses-link a selector or you can modify the snippet directly and add your preferred class or html.

    Hope this helps!

    Kind regards!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.