Adding CSS styles to CoursePress listing and redirecting users from the admin

Hello! I would like to add CSS so my CoursePress listings look similar to what you have on https://premium.wpmudev.org/academy/ can you add those for me?

I would also like to redirect all non-admin users from the dashboard. I’ve added a snippet of code to do this, but it blocks logins from my site’s front page too.

Here’s the snippet:

add_action( 'admin_init', 'redirect_none_admin' );

function redirect_none_admin(){
if(is_admin() && !current_user_can('manage_options')){
wp_redirect(home_url());
}
}

Also, the course page is not displaying breadcrumbs – can you add them so users can go back easily?

  • Ash
    • WordPress Hacker

    Hello Mikhail

    Please try the following css:

    .course_list_box_item{
    border: 15px solid #f4f4f4 !important;
    }
    .course_list_box_item.has-thumbnail .course-thumbnail{
    position: relative;
    left: -15px;
    top: -15px;
    }
    .course_list_box_item.has-thumbnail .course-thumbnail img{
    border: none !important;
    padding: 0 !important;
    }

    You can use this css in a plugin called Simple Custom CSS: https://wordpress.org/plugins/simple-custom-css/ Or you can use a child theme: https://premium.wpmudev.org/blog/how-to-create-wordpress-child-theme/

    Please note, you can’t have exact same design of academy as the html structure is different. You also need to upload a bit larger image.

    Please try the following code to prevent dashboard access for non-admins:

    function ace_block_wp_admin() {
    if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
    wp_safe_redirect( home_url() );
    exit;
    }
    }
    add_action( 'admin_init', 'ace_block_wp_admin' );

    You can use this code in your child theme’s functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    For breadcrumb, I am not quite sure I am sorry. I can see breadcrumb in the course page you shared. Please let me know if I am missing something.

    Have a nice day!

    Cheers,

    Ash

  • Mikhail
    • Flash Drive

    Thank you so much for the quick reply Ash thanks for the additional css too and Understand what you’re saying about the html markup difference.

    the code for the administrator as with the one that was initially posted works the problem lies within the fact that i’m also using the membership pro plugin to protect the pages on the website. so the login is essentially ran through memebership pro first on the front end and then if a user is logged in they shouldn’t be able to go to /wp-admin and see the dashboard if they are not an admin for the site. This however is not what happens when the code is active the and anyone tries to log in it says login failed to try again even with the correct credentials but then if you refresh the page you see that the login did actually work. but it would continue to say fail if you didnt refresh so you wouldn’t know that it worked.

    as for the breadcrumb it is there on the main course page, however, if you enter a single course there is no way to go back to all courses without pressing the back button on the browser or going back through the main menu, there should be a way within the individual course to go back the the main courses page without going through the main menu

  • Ash
    • WordPress Hacker

    Hello Mikhail

    About the dashboard related code, I saw the code was given my the chat support guy – but there is a difference between them. The difference is:

    ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )

    That means, when AJAX operation is going on, we will ignore the redirect. Membership login uses ajax operation. So, technically it should work and it’s normal that the code from live chat will fail in this case.

    If my code fails too, then the issue is with something else and we will need to take extra care for that.

    About the breadcrumb, are you using any plugin for that? If yes, would you please send me a link to that plugin? Or is it from coming from the theme you are using?

    Cheers, Ash

  • Nithin
    • Support Wizard

    Hi Mikhail,

    no plugin its coming from the theme itself.

    Sorry for the delay in getting back to you. I checked your website, and it seems like you are using the LearnPress plugin, instead of CoursePress plugin and the breadcrumbs are listed for single Course page, /courses/learning-excel/. Seems like you have resolved it via LearnPress plugin?

    and your code failed to redirect as well.

    I tested the code in my system, and I could confirm it's working fine when tested. The code seems to redirect non-admin users when the dashboard was accessed. Could I know where exactly the code is added?

    I checked the child themes functions.php file, but I wasn't able to find the relevant given code in there. Please advise, what's being missed so that we could help guide you better.

    Regards,

    Nithin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.