2013/12/27

WordPress | 密碼文章輸入框 get_the_password_form

在 Wordpress 中,密碼保護的文章預設不會產生摘要,只會顯示「受保護的文章不會產生摘要」,也不會有密碼輸入框讓你輸入,每次都要點進文章後才能輸入密碼,實在是有點不方便。



不過只要在 functions.php 加入以下語法,密碼保護文章的摘要就可以顯示密碼輸入框囉!

function excerpt_password_input( $excerpt ) {
    if ( post_password_required() )
        $excerpt = get_the_password_form();
    return $excerpt;
}
add_filter( 'the_excerpt', 'excerpt_password_input' );
/* 密碼提示 */ function my_password_form() { global $post; $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID ); $hint = get_post_meta( $post->ID, 'hint', true ); $o = '
' . "提示:$hint
" . '
'; return $o; } add_filter( 'the_password_form', 'my_password_form' );

0 comments:

張貼留言