在后台页面管理列表中隐藏特定的页面

对于WordPress多用户站点,隐藏一些比较重要的信息是很有必要的。有的时候,我们通过页面(Page)建立了一些很重要的功能页面,比如一些投稿页面、用户信息页面、前台布局页面等,我们当然不希望被其他用户看到这些页面。

pages-from-admin-wpdaxue_com

你可以在主题的 functions.php 中添加下面的代码:

add_action( 'pre_get_posts' ,'exclude_this_page' );
function exclude_this_page( $query ) {
        if( !is_admin() )
                return $query;
        global $pagenow;
        if( 'edit.php' == $pagenow && ( get_query_var('post_type') && 'page' == get_query_var('post_type') ) )
                $query->set( 'post__not_in', array(23,28,30) ); // 页面的ID
        return $query;
}

第3行 if( !is_admin() ) 判断,如果是网站管理员,就不隐藏,你也可以自己灵活地修改判断条件;根据自己的需要修改第 7 行的页面ID 。

来源:

https://www.wpdaxue.com/exclude-pages-from-admin-edit-pages-list.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32478.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?