Last active
April 7, 2016 04:50
-
-
Save igorbenic/72ff5b4e114b6e5e9be4cb3dde77b3b2 to your computer and use it in GitHub Desktop.
Understanding WordPress Menu Items | http://www.ibenic.com/understanding-wordpress-menu-items/
This file contains hidden or 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
| <?php | |
| function ibenic_custom_menu( $menu_item ) { | |
| // If we are in the admin area, skip this function | |
| if ( is_admin() ) { | |
| return $menu_item; | |
| } | |
| // If this isn't a Sample Page menu item, skip this function | |
| if ( $menu_item->title != "Sample Page" ) { | |
| return $menu_item; | |
| } | |
| if( !is_user_logged_in() ){ | |
| $menu_item->_invalid = true; | |
| } | |
| // If there is no url, don't render it | |
| if ( empty( $menu_item->url ) ) { | |
| $menu_item->_invalid = true; | |
| } | |
| return $menu_item; | |
| } | |
| add_filter( 'wp_setup_nav_menu_item', 'ibenic_custom_menu', 10, 1 ); |
This file contains hidden or 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
| <?php | |
| // Sample Page Menu Item | |
| WP_Post Object ( | |
| [ID] => 161 | |
| [post_author] => 1 | |
| [post_date] => 2016-03-26 17:59:07 | |
| [post_date_gmt] => 2016-03-26 17:59:07 | |
| [post_content] => | |
| [post_title] => | |
| [post_excerpt] => | |
| [post_status] => publish | |
| [comment_status] => closed | |
| [ping_status] => closed | |
| [post_password] => | |
| [post_name] => 161 | |
| [to_ping] => | |
| [pinged] => | |
| [post_modified] => 2016-04-06 14:09:26 | |
| [post_modified_gmt] => 2016-04-06 14:09:26 | |
| [post_content_filtered] => | |
| [post_parent] => 0 | |
| [guid] => http://localhost/wordpress/?p=161 | |
| [menu_order] => 2 | |
| [post_type] => nav_menu_item | |
| [post_mime_type] => | |
| [comment_count] => 0 | |
| [filter] => raw | |
| [db_id] => 161 | |
| [menu_item_parent] => 0 | |
| [object_id] => 2 | |
| [object] => page | |
| [type] => post_type | |
| [type_label] => Page | |
| [url] => http://localhost/wordpress/sample-page/ | |
| [title] => Sample Page | |
| [target] => | |
| [attr_title] => | |
| [description] => | |
| [classes] => Array ( [0] => ) | |
| [xfn] => | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment