Skip to content

Instantly share code, notes, and snippets.

@kubiqsk
Last active February 26, 2024 20:20
Show Gist options
  • Save kubiqsk/473a002094b959d18923b7f97e977638 to your computer and use it in GitHub Desktop.
Save kubiqsk/473a002094b959d18923b7f97e977638 to your computer and use it in GitHub Desktop.
Alternative menu item title
<?php
add_filter( 'wp_nav_menu_objects', function( $items, $args ){
if( $args->theme_location == 'main_nav' || $args->menu->term_id == 6 ){
foreach( $items as &$item ){
if( $item->auto_listed ){
$custom_menu_title = get_field( 'custom_menu_title', $item->ID );
if( $custom_menu_title ){
$item->title = $custom_menu_title;
}
}
}
}
return $items;
}, 10, 2 );
// support also orderby
add_filter( 'bmp_posts_args', function( $args ){
$args['meta_query'] = [
'relation' => 'OR',
[
'key' => 'custom_menu_title',
'compare' => 'EXISTS'
],
[
'key' => 'custom_menu_title',
'compare' => 'NOT EXISTS'
]
];
$args['orderby'] = [
'meta_value' => 'ASC',
'title' => 'ASC'
];
return $args;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment