Created
March 21, 2019 18:37
-
-
Save luclemo/bc81808f61ed6d9ef4e413c352a479b3 to your computer and use it in GitHub Desktop.
Add text to your password form, modify the HTML form, change the default `Protected:` title prefix. #wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* If you want to add text to your password form | |
* | |
* @link https://developer.wordpress.org/reference/hooks/the_password_form/ | |
*/ | |
add_action( 'the_password_form', 'll_the_password_form' ); | |
function ll_the_password_form( $output ) | |
{ | |
$before = ' Before '; // Modify this to your needs! | |
$after = ' After '; // Modify this to your needs! | |
return $before . $output . $after; | |
} | |
/** | |
* Modify the HTML form directly | |
* (The password field is limited to to 20 characters) | |
* | |
* @link https://developer.wordpress.org/reference/functions/get_the_password_form/ | |
*/ | |
add_filter( 'the_password_form', 'll_override_the_password_form' ); | |
function ll_override_the_password_form( $form = '' ) { | |
global $post; | |
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID ); | |
$form = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post"> | |
' . __( "To view this protected post, enter the password below:" ) . ' | |
<label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" /> | |
</form> | |
'; | |
return $form; | |
} | |
/** | |
* Change the default Protected: title prefix | |
* | |
* @link https://developer.wordpress.org/reference/hooks/protected_title_format/ | |
*/ | |
add_filter( 'protected_title_format', 'll_protected_title_format' ); | |
function ll_protected_title_format( $format ) | |
{ | |
$format = __( ' Members only! %s ' ); // Modify this to your needs! | |
return $format; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment