{"id":1278,"date":"2016-06-04T09:56:10","date_gmt":"2016-06-04T19:56:10","guid":{"rendered":"http:\/\/mymonkeydo.com\/?p=1278"},"modified":"2016-06-04T09:56:10","modified_gmt":"2016-06-04T19:56:10","slug":"wordpress-the_title-filter-changed-in-nav-menus","status":"publish","type":"post","link":"https:\/\/mymonkeydo.com\/wordpress-the_title-filter-changed-in-nav-menus\/","title":{"rendered":"WordPress the_title filter changed in nav menus"},"content":{"rendered":"
I haven’t had time to look into the exact reason or the exact version this changed, but as of at least WordPress version 4.5.2 the nav menu uses\u00a0the_title\u00a0multiple times for one item.<\/p>\n
For example if your theme used something like this:<\/p>\n
It would have one ” | ” after each menu title in previous versions, but in WordPress 4.5 ish it would show two ” | “. \u00a0Again, haven’t looked at the exact cause that changes this, but the solution is to check if the item you’re looking at is a nav_menu_item:
\nfunction menu_title_filter( $title ) {
\nreturn $title . ' | ';
\n}
\nadd_filter( 'the_title', 'menu_title_filter' );<\/code><\/p>\n
\n
\nfunction menu_title_filter( $title, $id ) {
\n$item = get_post( $id );
\nif ( $item->post_type != 'nav_menu_item') return $title;
\nreturn $title . ' | ';
\n}
\nadd_filter( 'the_title', 'menu_title_filter', 10, 2 );<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[2],"tags":[64],"yoast_head":"\n