admin管理员组文章数量:1393361
I have multiple pages with the same name under the different category at my wp site.
The issue I'm having is that it is hard to distinguish which I need in the Appearance > Menus section.
I was therefore looking for a hook to go trough the items, either in the accordion or in the menu items list on the admin page, but unable to found any.
Is there any hook or other way that could help me do this ?
I could of course edit nav-menus.php but it will be overwritten by the future updates.
Thanks in advance
I have multiple pages with the same name under the different category at my wp site.
The issue I'm having is that it is hard to distinguish which I need in the Appearance > Menus section.
I was therefore looking for a hook to go trough the items, either in the accordion or in the menu items list on the admin page, but unable to found any.
Is there any hook or other way that could help me do this ?
I could of course edit nav-menus.php but it will be overwritten by the future updates.
Thanks in advance
Share Improve this question edited Feb 10, 2020 at 12:40 Giedrius asked Feb 10, 2020 at 12:31 GiedriusGiedrius 11 bronze badge1 Answer
Reset to default 0There are not good/easy hooks to achieve this, but I think this is possible, just needs some work. I can give you general direction and some ideas.
You can use hooks on nav_menu_items_page
and nav_menu_items_page_recent
to return array of posts with changed title. They both may use the same function, like this
function my_nav_menu_items($posts, $args) {
foreach ($posts as $post) {
// get category name or whatever you need for title
$post->post_title = $post->post_title . " [..CATEGORY..]";
}
return $posts;
}
add_filter('nav_menu_items_page', 'my_nav_menu_items', 10, 2);
add_filter('nav_menu_items_page_recent', 'my_nav_menu_items', 10, 2);
But now you have another problem, your updated title will be used as menu link title when you save your menus. To prevent this you may try to add additional hook on wp_insert_post_data
or something like that, check for post_type
being nav_menu_item
and then remove your added category from title value. You some square brackets or distinctive separator to make this easier.
本文标签: adminAdd category label for appearance gt menus items
版权声明:本文标题:admin - Add category label for appearance > menus items 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744761653a2623789.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论