Coursepress Pro - Show Lection Title in Lection Units

I'm developing a course for a friend of mine in Coursepress. The Course is structured into 33 Steps, which is further broken down into pages. When viewing the course, the step title is never shown in the frontend, only the page titles. Is there any chance to get both titles onto the page view?

  • Kasia Swiderska
    • Support nomad

    Hello Martin,

    I'm extremely sorry for the delay on my end - I was dealing recently with health issues.

    So there is no our of the box way to do that. However, I have asked our Second Line Support Developers if that will be possible with some custom code and they will check that.

    kind regards,
    Kasia

  • Konstantinos Xenos
    • Rubber Duck Debugger

    Hi Martin ,

    I've made a mu-plugin for you so you can easily add the Unit titles above both Sections & Modules if you like.

    How to install:
    Always make sure to keep a backup of your site before changing/adding custom code.

    1] Navigate to your /wp-content/ directory and create a new one named mu-plugins if it doesn't exist.
    2] Inside the mu-plugins folder create a file named cp-add-unit-titles.php
    3] Edit the file and copy / paste this code snippet inside.

    <?php
    
    // Adds the Unit name in Modules.
    add_filter(
    	'coursepress_module_header',
    	function( $content, $module ) {
    		$title = '<h2>' . get_the_title( $module->post_parent ) . '</h2>';
    
    		$content = $title . $content;
    
    		return $content;
    	},
    	15,
    	2
    );
    
    // Adds the Unit name in Sections.
    add_filter(
    	'coursepress_template_focus_item_section',
    	function( $template, $a ) {
    		$title = '<h2>' . get_the_title( $a['unit'] ) . '</h2>';
    
    		$template = $title . $template;
    
    		return $template;
    	},
    	15,
    	3
    );

    4] Save and close the file.
    5] The final path should look like /wp-content/mu-plugins/cp-add-unit-titles.php
    6] Everything should work after that automatically.

    Tell me if you need any further help with this !

    Regards,
    Konstantinos

  • Martin
    • Flash Drive

    I finally got around to testing it. It seems like the first module, which adds to 'coursepress_module_header' adds it to every header possible within the module, I can't see, where the second snippet 'coursepress_template_focus_item_section' places the header. Is there a chance to add it only above the section title?

    As in the screenshot: The Section title "Schritt 1: Standortbestimmung" should not be placed above "Dein Lebenskreis" but above "Weiterkommen und Ziele definieren".

  • Kasia Swiderska
    • Support nomad

    Hello Martin,

    Thank for the access. So it seems that the code provided only works in the Focus mode when on your site course is in the Normal Mode view.
    I checked with the developer and that type of change will require a change in the plugin also.
    In the file: plugins\coursepress\2.0\include\coursepress\template\class-unit.php
    Line: 203

    Change from:
    $content .= '<h3 class="page-title unit-section-title">' . $page_title . '</h3>';

    To:
    $content .= apply_filters( 'custom_coursepress_unit_header', '<h3 class="page-title unit-section-title">' . $page_title . '</h3>', $unit_id );

    and in the mu-plugin you created before, remove the previous code and add this one:

    <?php
    
    // Adds the custom Unit name.
    add_filter(
        'custom_coursepress_unit_header',
        function( $html, $unit_id ) {
            $title = '<h2>' . get_the_title( $unit_id ) . '</h2>';
    
            $template = $title . $html;
    
            return $template;
        },
        15,
        2
    );

    kind regards,
    Kasia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.