I don't want our members to be redirected to the standard WP login form

Looking for support around the shortcodes. Using the echo do_shortcode( '[course_join_button course_id="'.$course->ID.'"]' ); in our theme but it's directing the user to the standard WP login form instead of the one I specified under General Settings. Have some additional issues with the same shortcode as well.

  • Ken Kimbrell

    Hello Matthew-

    I see you have an inquiry regarding our CoursePress Pro plugin and the use of shortcodes.

    I made a custom function explaining a way you could use this shortcode and have it redirect to your own custom login page if user is not logged in. see code below:

    function wpmu_custom_course_list(){
        $args = array('post_type' => 'course', 'post_per_page' => 10);
        $loop = new WP_Query($args);
    
        while($loop->have_posts() ) : $loop->the_post();
    
        global $post;
        $url  = get_the_permalink();
    
        if( !is_user_logged_in() ){
        echo "<a href='http://yoursite.com/custom-login'>";// if user is not logged in, redirect here
        }else{
        echo "<a href='{$url}'>";// if user is logged in, redirect here
        }
        echo the_title('<h2>','</h2>');
        echo "</a>";
        echo "<div class='course_content'>";
        echo the_content();
        echo "</div>";
        if( !is_user_logged_in() ){
        echo "<a href='http://yoursite.com/custom-login'>";// if user is not logged in, redirect here
        }else{
        echo "<a href='{$url}'>";// if user is logged in, redirect here
        }
        echo do_shortcode( '[course_join_button course_id="'.$post->ID.'"]' );
        echo "</a>";
        endwhile;
    
    }
    //Use [course_list] as the shortcode to call the function
    add_shortcode('course_list', 'wpmu_custom_course_list');

    While you may not need an entire custom post query of the course list. I am just providing it as an example, for a way you could use the shortcode and determine if the user is logged in. For example you could try this:

    global $post;
    $url  = get_the_permalink();
    
      if( !is_user_logged_in() ){
        echo "<a href='http://yoursite/custom-login.com'>";// if user is not logged in, redirect here
        }else{
        echo "<a href='{$url}'>";// if user is logged in, redirect here
        }
        echo do_shortcode( '[course_join_button course_id="'.$post->ID.'"]' );
        echo "</a>";

    Let me know if this helps!

    Take Care,

    Ken - WPMU DEV Support

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.