WordPress – Protect page by login

I’ve a site and I would create a simply “Members only” page.
I would add a protection to a page content so only editors and administrators can access.

This page should be visible to all users, but when a guest click on it, the page content is protected by username/password. When user fill these fields, the page automatically redirect to protect content.

Read More

Is there a plugin, or method, that I can consider?

Related posts

Leave a Reply

3 comments

  1. There probely is some plugin for this kind of stuff, i mostly build my own themes, and implement it there.

    if its just one page you want to protect, you could make a own template file for that page.
    if the page name is “secrets”, you could in the teames folder copy the page.php (or index.php) to page-secrets.php, and add some php code to protect that page.

    a relly simple version could be:

    <?php
            get_header();
            if($_POST['password'] == 'the password')
            {
                    ...
            }
            else
            {
                    echo "<h2>This page is password protected</h2>";
                    echo "<form action='?' method='post'>";
                    echo "<label><span>Password</span>";
                    echo "<input type='password' name='password' /></label>";
                    echo "<input type='submit' name='Authenticate' />";
                    echo "</form>";
            }
            get_footer();
    ?>
    

    where … is the copied content from page.php (or index.php) between the get_header(); and get_footer(); rows

  2. WordPress has builtin “password-protect page” feature. If you are using some kind of a standard theme, all you need is to set a password inside a “publish” box at the page editor page (password field is hidden behind some link).