Search
Close this search box.
Search
Close this search box.

Customizing And Styling The Password Protected Form

Edit Your functions.php File

Open up your functions.php file and add this block of code:

function my_password_form() {
    global $post;
    $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
    $o = '<form action="' . esc_url(site_url('wp-login.php?action=postpass', 'login_post')) . '" method="post">';
    $o .= __("To view this protected post, enter the password below:");
    $o .=' <label for="' . $label . '">' . __("Password:") . ' </label>';
    $o .= '<input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" />';
    $o .= '<input type="submit" name="Submit" value="' . esc_attr__("Submit") . '" />';
    $o .= '</form>';
    return $o;
}

add_filter('the_password_form', 'my_password_form');

Remove protected from password protected title

function the_title_trim($title) {
    $title = attribute_escape($title);
    $findthese = array(
        '#Protected:#',
        '#Private:#'
    );
    $replacewith = array(
        '', // What to replace "Protected:" with
        '' // What to replace "Private:" with
    );
    $title = preg_replace($findthese, $replacewith, $title);
    return $title;
}

add_filter('the_title', 'the_title_trim');