I'm trying to edit the template开发者_如何学Python page which is used when a page or post is password protected. I can't seem to have much luck locating it.
do you know where it is?
It's my understanding that the password protected pages/posts use the same templates are regular pages/posts. If you're looking to change the standard message "My post is password protected. Please ask me for a password:", try adding this code snippet (changing the text to read how you want) to your theme's function.php file:
function fb_the_password_form() {
global $post;
$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
$output = '<form action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post">
<p>' . __("My post is password protected. Please ask me for a password:") . '</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__("Submit") . '" /></p>
</form>';
return $output;
}
add_filter('the_password_form', 'fb_the_password_form');
I found this over at Change Wording for Password Page by WP Engineer.
In a child theme of twenty-thirteen, the above did not work. Instead, I used this code (unfortunately, I cannot remember who wrote it):
<?php
function my_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
' . __( "Some custom statement here.\nAnd a second line:\n" ) . '
<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><p style="font-size:18px;margin:0px; padding: 8px; background: lightblue; height: 40px; width: 400px; text-align: center;">Some other text here</p>
';
return $o;
}
add_filter( 'the_password_form', 'my_password_form' );
?>
精彩评论