Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从菜单中隐藏项目,以及在用户未登录时拒绝访问_Php_Wordpress - Fatal编程技术网

Php 从菜单中隐藏项目,以及在用户未登录时拒绝访问

Php 从菜单中隐藏项目,以及在用户未登录时拒绝访问,php,wordpress,Php,Wordpress,如果用户未登录,我可以从菜单中隐藏一个项目,通常如何禁用页面访问?因为这只能通过css限制访问。 这是我的子模板文件functions.php中的当前代码 add_action('wp_head','hide_menu'); function hide_menu() { if ( is_user_logged_in() ) { $output="<style> .navbar-nav.megamenu li:nth-child(2) { display:

如果用户未登录,我可以从菜单中隐藏一个项目,通常如何禁用页面访问?因为这只能通过css限制访问。 这是我的子模板文件functions.php中的当前代码

add_action('wp_head','hide_menu');

function hide_menu() { 
    if ( is_user_logged_in() ) {
        $output="<style> .navbar-nav.megamenu li:nth-child(2) { display: none; } </style>";
    } else {
        $output="<style> 
        .navbar-nav.megamenu li:nth-child(3) { display: none; } 
        .navbar-nav.megamenu li:nth-child(4) { display: none; }
        .navbar-nav.megamenu li:nth-child(5) { display: none; }
        .navbar-nav.megamenu li:nth-child(6) { display: none; }
        .pull-right.list-inline.acount li:nth-child(1) { display: none; }
        .pull-right.top-cart-wishlist { display: none; }
        </style>";
    }
    echo $output;
add_action('wp_head','hide_menu');
函数hide_menu(){
如果(用户是否已登录){
$output=“.navbar-nav.megamenu li:n子级(2){display:none;}”;
}否则{
$output=”
.navbar-nav.megamenu li:n子级(3){显示:无;}
.navbar-nav.megamenu li:n子级(4){显示:无;}
.navbar-nav.megamenu li:n子级(5){显示:无;}
.navbar-nav.megamenu li:n子级(6){显示:无;}
.pull-right.list-inline.a帐户li:n子项(1){display:none;}
.pull-right.top-cart-wishlist{display:none;}
";
}
echo$输出;
注意:我不想使用各种被禁用的插件,我在谷歌上找不到合适的答案,所以请寻求您的帮助


类似这样的内容?

您可以检查用户是否已登录,如果post id等于您不希望未登录用户访问的页面,并将其重定向到frontpage,请将其粘贴到页眉

    $front = get_home_url();
    $post = get_post();
    $user = wp_get_current_user();
    if($user->ID < 1){
        if($post->ID == your-post-id-here){
           header( "Location: $front" );
        }
    }
$front=get_home_url();
$post=get_post();
$user=wp_get_current_user();
如果($user->ID<1){
如果($post->ID==此处的帖子ID){
标题(“位置:$front”);
}
}

page edit->right pane->document->visibility->private@Banzay不,这只是给管理员的,上面写着你的帖子id,把你不想让注销用户访问的页面的帖子id放在这里