Edit the WordPress password form in your theme

WordPress is a popular content management system used to create and manage websites. It is widely used by bloggers, businesses, and web developers alike. One of the most important features of WordPress is its password form. This form is used to protect the website from unauthorized access and keep user data safe.

The WordPress password form is a simple and effective way to secure user data. It requires a password before access is granted to the post’s data.

Add the code in the “functions.php” file.

function hs_password_form( $post = 0 ) {
    $post   = get_post( $post );
    $label  = 'pwbox-' . ( empty( $post->ID ) ? wp_rand() : $post->ID );
    $output = '<p class="post-password-message">' . esc_html__( 'This content is password protected. Please enter a password to view.', 'text-domain' ) . '</p>
	<form action="' . esc_url( home_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
	<label class="post-password-form__label" for="' . esc_attr( $label ) . '">' . esc_html_x( 'Password', 'Post password form', 'text-domain' ) . '</label><input class="post-password-form__input" name="post_password" id="' . esc_attr( $label ) . '" type="password" size="20" /><input type="submit" class="post-password-form__submit" name="' . esc_attr_x( 'Submit', 'Post password form', 'text-domain' ) . '" value="' . esc_attr_x( 'Enter', 'Post password form', 'text-domain' ) . '" /></form>
	';
    return $output;
}
add_filter( 'the_password_form', 'hs_password_form' );
Shopping Cart