Reputation: 23
I was able to hide an item from the menu if the user is not logged in, how do I generally disable page access as well? because this is only through css restricted access. This is my current code from file functions.php from my Child-Template.
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;
Note: I do not want to use various plugins that are disabled, and I couldn't find an adequate answer on google so please ask for your help.
something like this? enter image description here
Upvotes: 0
Views: 67
Reputation: 105
You can check if user is logged in and if post id equals the page you dont want the not logged in user to access and redirect them to frontpage, paste this in header right before
$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" );
}
}
Upvotes: 1