Using functions.php file in the Coursepress

Hi
Before CoursePress 2.0.1 we was using an Child theme for Coursepress plugin (theme) folder. But that end out badly in the upgrade.

So is it possible to put functions into the Coursepress Pro theme file, but some other plugin, so we can edit it but be ready for updates?

I will like to have this code in there:
/* reload theme - START */
add_action( 'load-themes.php', 'my_customize_redirect' );
function my_customize_redirect() {

if ( strstr( wp_get_referer(), '/wp-admin/customize.php' ) )
{
wp_safe_redirect( site_url() );
exit();
}
}
/* reload theme - END */

  • Luís

    Hi morfjord ,

    Hope you're doing well today!

    Regarding to your questions:

    1) If I understood well the intent, maybe the best option should be use that code in a mu-plugin.

    It will be automatically activated and separated from the theme, however, you should always check after the update to see if it generates any conflict.

    1.1) Download the .zip file attached and unzip it;

    1.2) Using FTP access, upload "customize-redirect.php" to "wp-content/mu-plugins" folder;

    Note: If you don't have this folder, please, create it.

    2) Regarding to the stylesheet, you can use a mu-plugin too, checking if the blog uses the "CoursePress theme" and if yes, load your custom stylesheet. Something like:

    $theme = wp_get_theme(); // gets the current theme
    
    if ('coursepress' == $theme->name) {
    
    	function my_coursepress_styles() {
        	wp_enqueue_style( 'my_styles', get_template_directory_uri() . '/my_styles.css');
    	}
    	add_action( 'wp_enqueue_scripts', 'my_coursepress_styles' );
    }

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

  • morfjord

    Thanks awesome support Luís

    But I cant get the q2) to work:
    $theme = wp_get_theme(); // gets the current theme

    if ('coursepress' == $theme->name) {

    function my_coursepress_styles() {
    wp_enqueue_style( 'my_styles', get_template_directory_uri() . '/styles.css');
    }
    add_action( 'wp_enqueue_scripts', 'my_coursepress_styles' );
    }

    All the blogs has the same theme, but the main site are using an other theme.

    In CoursePress the folder is: https://simplylearn.no/wp-content/plugins/coursepress/2.0/themes/coursepress/style.css

    but in the main site it is:
    https://simplylearn.no/wp-content/themes/bb-theme-child/style.css

    So how will the code then be?
    And where do I do the custom CSS? Where do I locate: my_coursepress_styles?

  • Luís

    Hi morfjord ,

    Sorry for the lack of information in my previous reply. From what I understood, the intention is create a new stylesheet for the CoursePress theme, to override the default styles, right?

    If yes, let's say that you created a stylesheet with the name "my_styles.css".

    In the previous code shared, this "my_styles.css" should be placed inside the coursepress theme folder, we are giving the path to the theme folder in the "enqueue":

    wp_enqueue_style( 'my_styles', get_template_directory_uri() . '/my_styles.css');

    All the custom CSS will be placed in this stylesheet: "my_styles.css".

    As you don't want to create a child theme, and if I am not missing something, I think this is the best option.

    Cheers, Luís