Last active
December 21, 2015 13:19
-
-
Save tonykwon/6312113 to your computer and use it in GitHub Desktop.
Hiding non-published post menu items from WordPress Menu - for post_type page and post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'wp_get_nav_menu_items', 'hide_non_published_menu_items', 10, 3 ); | |
function hide_non_published_menu_items( $items, $menu, $args ) { | |
if ( $items ) { | |
foreach( $items as $k => $item ) { | |
// use $item->post_type if you want to apply this to custom post types | |
switch( $item->object ) { | |
case 'page': | |
case 'post': | |
if ( get_post_status( absInt($item->object_id) ) != 'publish' ) { | |
unset( $items[$k] ); | |
} | |
break; | |
} | |
} | |
return $items; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment