如果你有習慣使用密碼鎖定文章提供給特定人士觀看但不想網頁上公開顯示「受保護的文章:XXXXX」時,可以考慮採用隱藏並直接提供給對方文章網址的方式來觀看密碼文章。
首先開啟你目前使用的佈景主題中的 functions.php 檔案,並於頁尾 ?> 之前插入以下的程式碼:
// Filter to hide protected posts
function exclude_protected($where) {
global $wpdb;
return $where .= " AND {$wpdb->posts}.post_password = '' ";
}
// Decide where to display them
function exclude_protected_action($query) {
if( !is_single() && !is_page() && !is_admin() ) {
add_filter( 'posts_where', 'exclude_protected' );
}
}
// Action to queue the filter at the right time
add_action('pre_get_posts', 'exclude_protected_action');
這樣就可以隱藏 密碼文章 不顯示於公開的網頁上了。
資料來源:https://codex.wordpress.org/Using_Password_Protection