Hi there,
really great your Enfold theme!
I’ve already used it for 30 projects.-)
I just want to get rid of a suggestion for improvement:
I always use a menu as the “Enfold Main Menu” for navigation, because it’s easier to design without CSS. Editors often want to hide pages temporarily, but when pages are drafted, the menu items are still displayed. Only pages that are in the recycle bin no longer appear in the menu.
Also, couldn’t you treat draft pages like deleted pages in the menus, i.e. don’t show them again until they’re published again?
I think that makes more sense than a “page not found”.
Regards
Stephan
Hey Stephan,
Thank you for the inquiry.
The wp_nav_menu, which is the function used to display the menu items, doesn’t have a parameter to exclude draft pages. This is the reason why the item still display in the menu even when the corresponding page have been reverted back to draft status. But it should be possible to hide those items using a filter. The filter below checks and hides the item based on the page or post status.
/**
* hide draft pages from the menu
*/
function avf_wp_nav_menu_objects_mod($items, $args) {
foreach ($items as $i => $obj) {
if (!is_user_logged_in () && 'draft' == get_post_status ($obj->object_id)) {
unset ($items[$i]);
}
}
return $items;
}
add_filter ('wp_nav_menu_objects', 'avf_wp_nav_menu_objects_mod', 10, 2);
Best regards,
Ismael
Hi Ismael,
that works great!
I installed it via child theme.
Thanks very much!
Regards
Stephan
Hi Stephan,
Great, I’m glad that Ismael could help you out. Please open a new thread if you should have any further questions or problems.
Best regards,
Rikard
This is only – if we do not use the enfold menu? I did not know this.