2

There's a specific category on my website that should be restricted to teachers only using login. However, I don't want to hassle the teachers with the not so welcoming admin Wordpress offers. I would like to offer a "lightbox" that's basically a login that doesn't automatically forward to the admin, but only makes the teachers category content available. Do you know any plugin that allows that? Thanks, Sarit

1 Answer 1

2

Don't know about a plugin that does that for you but you can use the WordPress native Thickbox:

enter image description here

First include the Thickbox script and style in your category only if the user is not logged in (simply copy/paste in your theme's functions.php file)

function add_thickbox_script_and_style(){
    if(is_category('YOUR_CATEGORY') && !is_user_logged_in()){
        wp_enqueue_script('jquery');
        wp_enqueue_script('thickbox',null,array('jquery'));
        wp_enqueue_style('thickbox.css', '/'.WPINC.'/js/thickbox/thickbox.css', null, '1.0');
    }
}
add_action('init','add_thickbox_script_and_style');

Then open up your category.php (or archive.php depending on your theme , or even better is a custom file for that category category-id.php) and add this code before the loop:

if (is_category('YOUR_CATEGORY') && !is_user_logged_in()){
    echo '<div id="lform" style="display:none;">';
    wp_login_form();
    echo '</div>';
    echo 'Please <a class="thickbox" href="#TB_inline?height=200&width=200&inlineId=lform">Login</a> to see the content';
}else{


//your loop goes here

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.