Get a free advice now!

    Pick the topic

    Developer OutsourcingWeb developingApp developingDigital MarketingeCommerce systemseEntertainment systems

    Thank you for your message. It has been sent.


    WP Password protected page

    WP Password protected page

    CHALLENGE: share secret content protected by a password form

    SOLUTION: create a new WordPress page with Visibility: Password protected

    We often need a simple and straightforward way to share content only with a specific group of people. By default, content is restricted, only visitors with password can access it. WordPress CMS has this feature built in – when creating a new page, go to the ‘Publish’ metabox on the right and change the ‘Visibility’ parameter.

    Password template

    Your WordPress theme might already include the defined special PHP template for handling the wp password form. If not, here is sample code. The file should be added in your child theme / or parent theme directory.

     * // tpl-password-protected.php
     * Template Name: Password protected content
    get_header(); ?>
    global $post;
    $protect_content = true;
    if (!post_password_required($post)) {
        // if there is no password required
        // display the content
        $protect_content = false;
    } else {
        echo '<div class="container py-5">';
        echo get_the_password_form();
        echo '</div>';
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
            while (have_posts()) :
                the_post(); ?>
                <div class="entry-content">
                    <?php the_content(); ?>
                            'before' => '<div class="page-links">' . __('Pages:', 'storefront'),
                            'after' => '</div>',
                </div><!-- .entry-content -->
            endwhile; // End of the loop.
        </main><!-- #main -->
    </div><!-- #primary -->

    Edit page Attributes

    The last step will be to enable the proper Template using the ‘Page Attributes’ metabox. The ‘Password protected content’ template should be chosen from select. Make sure to Update/Save Page after the change. That’s it, now your page content is protected. Text will not be visible in search results. On page visit, there will be a message: “This content is password protected. To view it please enter your password below:” and a form with password input will be provided. Filling in the password is required to see restricted content.

    WordPress dashboard publication options
    Password protection window with a box to type in the password

    Follow us for more useful tips and guidelines.

    0 response

    Add comment

    Your email address will not be published. Required fields are marked *

    Popular news

    Support – Tips and Tricks
    All tips in one place, and the database keeps growing. Stay up to date and optimize your work!

    Contact us