Change Default Text on Protected Posts

By default, WordPress will display the following text for password protected posts,

This post is password protected. To view it please enter your password below:

This is determined by Line 1146 at wp-includes/post-template.php. What if you wanted to change that output to something else? One solution would be to simply edit Line 1146 at wp-includes/post-template.php. Of course editing core files is never a good idea unless you know what you are doing. A much better solution is to create a new function and add a filter.

Add the following to your theme's functions.php file,

add_filter( 'the_password_form', 'custom_password_form' );
function custom_password_form() {
	global $post;
	$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
	$o = '<form class="protected-post-form" action="' . get_option('siteurl') . '/wp-pass.php" method="post">
	' . __( "This post is password protected. To view it please enter your password below:" ) . '
	<label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
	</form>
	';
	return $o;
}

Edit the appropriate text above.

Note that the new function has been assigned a class > protected-post-form. To make use of this simply add .protected-post-form to your theme's style sheet along with whatever styling rules you want. For instance, using the default Kubrick theme I added the following to the style sheet,

.protected-post-form {
      background:#FF0000;
      color:#fff;
      border:1px solid #000;
}

This is the result, (click image to enlarge)

protected

via the WordPress Support Forum.

About the author
Len has been blogging for over 10 years and is a rabid WordPress fan. In addition to blogging here you can find him writing the occasional article and toiling away in the forums at WeblogToolsCollection.com. He also hangs out at the WordPress support forums lending a hand where he can. You can find his political scribblings at RiteTurnOnly.com

One Response to “Change Default Text on Protected Posts”

  1. [...] This post was mentioned on Twitter by Leland and James Fisher, WordPress Canada. WordPress Canada said: WordPress Canada New Post: Change Default Text on Protected Posts #wordpress http://ow.ly/CxP9 [...]

Leave a Reply

CommentLuv Enabled