Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: [RESOLVED]Hide pages from non-members

@aces

Participant

One way of doing that is by serving different menus depending whether someone is logged in or not such as
`
<?php
// https://codex.wordpress.org/Function_Reference/wp_get_current_user
$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) {
wp_nav_menu( array( ‘container’ => false, ‘menu_id’ => ‘nav’, ‘theme_location’ => ‘secondary-menu’, ‘fallback_cb’ => ” ) );
// Not logged in.
} else {
wp_nav_menu( array( ‘container’ => false, ‘menu_id’ => ‘nav’, ‘theme_location’ => ‘primary’, ‘fallback_cb’ => ” ) );
// Logged in.
}
?>
`
or another approach:
`
<?php
if ( is_user_logged_in() ) {
wp_nav_menu( array( ‘container’ => false, ‘menu_id’ => ‘nav’, ‘theme_location’ => ‘primary’, ‘fallback_cb’ => ” ) );
} else {
wp_nav_menu( array( ‘container’ => false, ‘menu_id’ => ‘nav’, ‘theme_location’ => ‘secondary-menu’, ‘fallback_cb’ => ” ) );
}
?>
`
replacing the `wp_nav_menu` bit in the ( child ) theme’s header.php file. It may need adapting depending on theme etc. Remember to make backups before editing!

Then use the walled garden or similar techniques to redirect users if they try to reach the page directly…

Skip to toolbar