Wanted to change CoursePress Login Redirect to some other page

Hi,
I have installed coursePress Pro with unchecked Login Redirect option. Even , I have added the login Redirect plugin onto the site, and respective URL in that very section.
But, nothing positive, it leads me to /courses-dashboard instead of that specific page.

Even, I have added this below code in function.php. but , no effect:
<?php
add_filter( 'login_redirect', 'coursepress_redirect', 99 );
function coursepress_redirect() {
$redirect_url = site_url('URL NAME');

wp_redirect($redirect_url);
exit;
}

Upon Registration I want he needs to get to this page, not onto courses-dashboard.
Please Help!!

  • Bojan Radonic

    Hey there @Adil, hope you're well today!

    Using the filter will work only on default WordPress login form. This is what you should insert into your child theme functions.php:

    add_filter( 'login_redirect', 'coursepress_redirect', 9 );
    function coursepress_redirect($redirect_url) {
    $redirect_url = site_url('/sample-page');
    
    return $redirect_url;
    }

    Replace /sample-page with the page where you want users to be redirected after the login.

    For student login you could use the this template that I've created here. Unzip the file and open it with text editor of your choice and replace dummy URL on line 25 then save changes and place student-login.php into your child theme. It's important that you use child theme so these changes are not lost once the update comes.

    This should redirect users to the page of your choice after student login.

    Please let me know if this helps :slight_smile:

    Best regards,
    Bojan

  • Bojan Radonic

    Hey John Taylor,

    I just tested the code (I'm assuming you're referring to the template file I've attached) and it seems to be working just fine (see video http://screencast.com/t/phu0Vs4eMQi), can you please let me know which theme are you using? I've tested on TwentySixteen and everything seems to be working just fine, please make sure you're doing the following:

    1. Paste file into the root folder of your theme
    2. open the file and edit line 25, replace "http://Insert_URL_here/" with an actual URL where you want to redirect
    *3. In case you want to use custom login page too, then:
    3a: create a page
    3b: select Student Login as page template for that page.

    I've slightly modified the code so you can replace it with this one here:

    <?php
    /*
    Template Name: Student Login
    */
    
    if (is_user_logged_in() ) {
        wp_redirect ( home_url() );
        exit;
    }
    
    get_header(); ?>
    
    <?php
    global $post;
    ?>
    	<div id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
    
    					<?php
    
    $redirect_url = '';
    
    if ( ! empty( $_REQUEST['redirect_url'] ) ) {
    
    	$redirect_url = $_REQUEST['redirect_url'];
    
    }
    
    echo do_shortcode( '[course_signup page="login" login_title="" redirect_url="http://Insert_URL_here/" signup_url="' . CoursePress::instance()->get_signup_slug( true ) . '" logout_url="' . CoursePress::instance()->get_signup_slug( true ) . '"]' );
     ?>
    
    		</main><!-- #main -->
    	</div><!-- #primary -->
    
    <?php get_sidebar( 'footer' ); ?>
    <?php get_footer(); ?>
    
    <?php
    
    $redirect_url = '';
    
    if ( ! empty( $_REQUEST['redirect_url'] ) ) {
    
    	$redirect_url = $_REQUEST['redirect_url'];
    
    }
    
    echo do_shortcode( '[course_signup page="login" login_title="" redirect_url="http://www.google.com/" signup_url="' . CoursePress::instance()->get_signup_slug( true ) . '" logout_url="' . CoursePress::instance()->get_signup_slug( true ) . '"]' );

    Hope this helps :slight_smile:

    Cheers,
    Bojan