wordpress自定义密码文章的提示文字
wordpress有些文章需要加密,但提示文字不是很友好,今天老杨就记录一下自定义密码文章的提示文字的方法。
wordpress默认文字提示
官方译文如下
老杨这里稍作修改,添加加密提示,效果如下:

wordpress自定义密码文章的提示文字
代码如下
/**
* WordPress 自定义密码文章的提示文字
* 钩子:the_password_form
* 函数:get_the_password_form()
* 位置:/wp-includes/post-template.php
* 详解:https://developer.wordpress.org/reference/hooks/the_password_form/
* 来源:https://yangjunwei.com/3688.html
*/
add_filter( 'the_password_form', 'haibor_custom_password_form' );
function haibor_custom_password_form() {
$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>' . __( '本文受密码保护,请输入访问密码:' ) . ' <a href="'.get_option( 'siteurl' ).'/about-password-articles">为什么加密?</a></p>
<p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form>
';
return $output;
}