apply_filters( 'the_password_form', string $output, WP_Post $post )

Filters the HTML output for the protected post password form.


Description

If modifying the password field, please note that the core database schema limits the password field to 20 characters regardless of the value of the size attribute in the form input.


Top ↑

Parameters

$output string
The password form HTML output.
$post WP_Post
Post object.

Top ↑

Source

File: wp-includes/post-template.php. View all references

return apply_filters( 'the_password_form', $output, $post );


Top ↑

Changelog

Changelog
Version Description
5.8.0 Added the $post parameter.
2.7.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Deepak Kumar

    This is a working example and 9999 is the priority and you can adjust accordingly.

    function wpdocs_custom_password_form() {
    	global $post;
    
    	$loginurl = site_url() . '/wp-login.php?action=postpass';
    	$label = 'pwbox-' . ( ! empty( $post->ID ) ? $post->ID : rand() );
    
    	ob_start();
    	?>
    
    	<style>
    		.center-custom { margin: 0; position: absolute; top: 50%; left: 50%; -ms-transform: translate( -50%, -50% ); transform: translate( -50%, -50% ); }
    		.post-password-label { color: #fff; }
    		.post-password-class { width: 100% !important; }
    		.post-password-class:focus { color: #fff !important; border-color: #fff !important; }
    		@media only screen and ( max-width: 600px ) {
    			.center-custom {
    				width: 85%;
    			}
    		}
    	</style>
    	<div class="container-custom">			
    		<form action="<?php echo esc_attr( $loginurl ) ?>" method="post" class="center-custom search-form" role="search">
    			<label class="post-password-label"><?php esc_attr_e( "To view this protected post, enter the password below:" ) ?></label>
    			<label for="<?php echo esc_attr( $label ) ?>" class="post-password-label"><?php _e( "Password:" ) ?></label>
    			<input name="post_password" id="<?php echo esc_attr( $label ) ?>" class="input post-password-class" type="text" placeholder="Enter your access code provided by your concierge" />
    			<input type="submit" name="Submit" class="button" value="<?php esc_attr_e( "Access" ) ?>" />			
    		</form>
    	</div>
    
    	<?php
    	return ob_get_clean();
    }	
    add_filter( 'the_password_form', 'wpdocs_custom_password_form', 9999 );

You must log in before being able to contribute a note or feedback.