Template Overrides Not Working

Hello:

I have a developer working on adding some styling to the coursepress pages and he is running into some issues involving overriding the plugin templates. Here is his question for the CoursePress Support team:


Hi, I am trying to override template files used for the Coursepress plugin. To do this I have moved the relevant file from plugins/coursepress/themes/coursepress to the theme that we are using.

When I do this the pages will display but it will be missing data. For example I wanted to customize the units page so I moved:

plugins/coursepress/themes/coursepress/archive-unit.php to:

/wp-content/themes/my_theme_name/archive-unit.php

what this will display is the content in a full width from the screen (no container div) and the percentages will not display anything.

Can you Please advise how to override the templates which Coursepress uses.

  • Milan
    • WordPress Wizard

    Hey @Nigel,

    Hope you’re well today! :slight_smile: Welcome to WPMU DEV!

    CoursePress uses the default theme post/page templates

    If you open up CoursePress/includes/templates, you can copy those templates to your active theme to override the default ones, you can then make any modifications there.

    Let me know how it goes.

    Best Regards,

    Milan Savaliya.

  • Nigel
    • Site Builder, Child of Zeus

    Hi:

    Thanks, the developer said that helped but now he has another question – I have posted it below. Can you help me with a response to him? Thanks very much!


    Hi, I’ve managed to created new templates from the “coursePress/includes/templates” directory but I have a question about shortcodes. For example in the archive-unit.php file there is some short code called to process the percentages (the shortcode is called “course_unit_percent”:wink:. I would like to override this shortcode to add extra HTML mark up. Please can you advise the best method to do this.

  • Milan
    • WordPress Wizard

    Hello @Nigel,

    I am glad that it helped your developer.

    At this moment there isn’t any hook or filter used in course_unit_percent shortcode so basically there isn’t any out of box way you can customize its markup. However your developer can edit plugin’s /includes/classes/class.shortcodes.php file’s ‘”course_unit_percent” function to customize shortcode output.

    Another approach you can use is, create new function in same file as member function of class “CoursePress_Shortcodes” and then copy whole code of “course_unit_percent” function in it. And then finally change reference of shortcode handler function to your customized function by editing line no 81 of file /includes/classes/class.shortcodes.php as below,

    add_shortcode( 'course_unit_percent', array( &$this, 'my_customized_course_unit_percent' ) );

    where “my_customized_course_unit_percent'” will be the customized handler function your developer has to create.

    Here please note that change made in core files won’t be preserved when plugin gets updated. So one suggestion is to take backup of your code before you start making changes to core files.

    I hope this helps you.

    Please let me know if there is anything else I can help you with.

    Cheers,

    Milan Savaliya.

  • Nigel
    • Site Builder, Child of Zeus

    Hi:

    Thanks for the reply. The developer has two more questions as follows:

    1. For the course details page we have overriden the template. We are using the file “content-course-overview.php”. We want to show the menu which are available on the other course pages however, when we call the shortcode we are only getting three menu items “Units, Notifications, Course details”. Is there any specific shortcode we need to call to get all of the menu items showing on this page?

    2. We have overridden the single unit pages (single-unit.php). This has worked but one of the titles is missing on the overridden file. The shortcode which is used for this in the original file is “course_unit_page_title” which on the overridden file doesn’t display anything. Please can you advise why this might be happening?

    Thanks very much!

  • Milan
    • WordPress Wizard

    Hello @Nigel,

    Hope you are doing good. :slight_smile:

    Let me go bit by bit to answer your questions. :slight_smile:

    Is there any specific shortcode we need to call to get all of the menu items showing on this page?

    As far as I know there isn’t any shortcode available for such menu functionality. Actually menu mechanism handled by theme provided menu locations. When you add menu with Register Nav Menus it displays menu selection entry under Appereance > Menus page. Make sure you’ve selected your current menu set and assigned it to one of then menu location provided by your theme. Please review screenshot for more details on this.

    If you are unsure about how to create and manage menu you can follow this nice article.

    https://codex.wordpress.org/Appearance_Menus_Screen

    We have overridden the single unit pages (single-unit.php). This has worked but one of the titles is missing on the overridden file. The shortcode which is used for this in the original file is “course_unit_page_title” which on the overridden file doesn’t display anything. Please can you advise why this might be happening?

    This shortcode is working fine on my sandbox site and I’ve attached screenshot for your confirmation please review it too, it may be possible that you might not have specified shortcode’s “show_unit_title” parameter to false. Also every shortcode provided by CoursePress is not echo content every time. Sometimes shortcode returns value do you may have to use echo externally like,

    <?php echo do_shortcode('[course_unit_page_title.... show_unit_title="yes"]'); ?>

    Cheers,

    Milan Savaliya.

    [attachments are only viewable by logged-in members] [attachments are only viewable by logged-in members]