Coursepress Pro - Show unit title on page.

How do I show the UNIT TITLE on a custom page?
I have a course with lots of units, but no way to tell what page I am on.
A title would fix this but can't find a unit title shortcode?

Any help appreciated.

  • Nastia
    • Support Rock Star

    Hello lowercase , I hope all is well!

    I've tested the Coursepress Pro plugin on my site with CoursePress theme and the unit title is showing up from my end.

    The Unit section can be set inside the Unit's settings

    Also, in order to show a page title inside a unit, please check "Show section header as part of a unit option in Unit's Settings, under the Unit Sections description.

    If you still have an issue with showing the page title, please grant access from WPMU DEV > Support so I ca have a closer look.

    Let me know how it goes!


  • lowercase
    • Site Builder, Child of Zeus

    Hi Nastia

    I agree the title shows with the Coursepress theme active, but it does not show with any other theme - either custom ones or the wordpress default themes.

    It seems like it is a vital part of the page layout and should work with any theme - especially those Wordpress default themes. Each of my units have titles set but they do not display on my unit pages leaving users stranded as to where they are.

    Any thoughts as to how to make this function as it should? I've granted you access.

  • Sajid
    • DEV MAN’s Sidekick

    Hello lowercase,
    Hope you are doing good today :slight_smile:

    Yes, I can confirm that Unit Title does not show up on unit detail page while using default WordPress theme.

    However, the good news is that CoursePress use custom post types. This means we can simply override the template by creating single-unit.php file in your current theme (child theme if you are using a paid theme).

    Right now, you can simply download the attached file, unzip it and move it to your themes folder.

    But it is highly recommended to take backup of your site first before making any changes specially in code, with a backup/restore plugin like Snapshot Pro.

    It should work automatically. But if you notice any styling issues, then please post the entire code of single.php file of your theme on pastebin and share the link here. I will modify the code, so it preserve the look and feel of your current active theme.

    Hope that helps! Feel free to post a reply if you need further assistance :slight_smile:

    Best Regards,

  • todor
    • The Incredible Code Injector

    Here is the solution I made, without template files. It uses the hooks provided in CoursePress. I add it in a plugin, but should work in the theme functions file too:

    add_action( 'coursepress_normal_items_loaded', 'do_before_cp_section_modules', 9999999999, 3 );
    $global_unit_id_variable = 0;
    function do_before_cp_section_modules( $course_id, $unit_id, $page ) {
        global $global_unit_id_variable;
        $global_unit_id_variable = $unit_id;
        add_filter( 'coursepress_before_unit_modules', 'add_unit_title_before_unit_modules', 9999999999 );
    function add_unit_title_before_unit_modules( $content ) {
        global $global_unit_id_variable;
        return $content . '<h2>' . get_the_title( $global_unit_id_variable ) . '</h2>';

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.