get_the_password_form( int|WP_Post $post )

Retrieve protected post password form content.


Parameters Parameters

$post

(int|WP_Post) (Optional) Post ID or WP_Post object. Default is global $post.


Top ↑

Return Return

(string) HTML content for password form for password protected post.



Top ↑

Source Source

File: wp-includes/post-template.php

function get_the_password_form( $post = 0 ) {
	$post   = get_post( $post );
	$label  = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
	$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
	<p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
	<p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form>
	';

	/**
	 * Filters the HTML output for the protected post password form.
	 *
	 * 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.
	 *
	 * @since 2.7.0
	 *
	 * @param string $output The password form HTML output.
	 */
	return apply_filters( 'the_password_form', $output );
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by wplmillet

    Example:

    add_filter( 'the_password_form', 'wporg_password_form' );
    function wporg_password_form() {
        global $post;
        $label = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
        $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
        ' . esc_html__( 'New Text for my protected post', 'text-domain' ) . '
        <label class="pass-label" for="' . $label . '">' . esc_html__( 'Password:', 'text-domain' ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" style="background: #ffffff; border:1px solid #999; color:#333333; padding:10px;" size="20" /><input type="submit" name="Submit" class="button" value="' . esc_attr__( 'Submit', 'text-domain' ) . '" />
        </form><p class="text-below">' . esc_html__( 'Additional text to be placed below', 'text-domain' ) . '</p>
        ';
        return $output;
    }

    And you can use css like :

    .text-below {
    	color : red;
    	font-size:14px;
    	margin:0;
    	padding:10px
    }

    and hide or modifiy label :

    .pass-label {
    display : none;
    }

    And adapt the button too : :

    .button {
        background-color: #000;
        color:#fff;
        border: 0;
        margin: 0;
        height: 33px;
        padding: 0 6px 6px 6px;
        font-size: 15px;
    }

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