Edit WordPress password form in theme

Add the code in “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