Add button close to the Unit title

I am creating a courses site specific to childrens. When accessing to the Units list, it's a bit hard to understand that we need to click on the unit title to start the course.

It's possible to add a button after the title to link to the unit or make it more clear for young people to start the course ?


    Hi Emídio ,

    You can add a direct link to first unit in title with the following snippet:

    add_filter( 'the_title', function( $the_title ){
    	global $id, $post;
    	if( $id && $post &&  $post->post_type == "course" ){
    		$units = CoursePress_Data_Course::get_units( $id );
    		if( is_array( $units ) && ! empty( $units ) && is_user_logged_in() ){
    			$user_id = get_current_user_id();
    			$unit = $units[0];
    			if( CoursePress_Data_Student::is_enrolled_in_course( $user_id, $id ) ){
    				$unit_link = CoursePress_Data_Unit::get_unit_url( $unit->ID );
    				$the_title .= ' <span style="display:inline-block; font-size: 16px;"><a class="apply-button apply-button-enrolled " href="'. $unit_link .'">Start course!</a></span>';
    	return $the_title;
    }, 10 );

    You can add the above snippet in a mu-plugin or your theme's functions.php file.

    Hope this helps!



    Hi Emídio ,

    Thanks for clarification

    Unfortunately I didn't find any hook available for this. Instead of modifying plugin core files I would suggest adding the following snippet:

    add_action( 'wp_footer', function(){
    	global $post;
    	if( isset( $post->post_type ) && $post->post_type == 'unit_archive' ){
    		<script type="text/javascript">
    			$( '.units-archive-list .unit-archive-single' ).each(function(){
    				var unit_link = $( this ).find( 'a.unit-archive-single-title' );
    				var unit_href = unit_link.attr( 'href' );
    				var enter_button = $( '<span/>' );
    				enter_button.html( 'Start unit' );
    				enter_button.addClass( 'apply-button apply-button-enrolled' );
    				enter_button.css( 'display', 'inline' );
    				unit_link.append( enter_button );
    }, 10 );

    You can add this in your child theme's functions.php or in a mu-plugin.

    Please let us know if this help do what you need