Last active
October 29, 2024 07:15
-
-
Save wpexplorer/6416006 to your computer and use it in GitHub Desktop.
Add slug to menu ID for pages in WordPress menu
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('nav_menu_link_attributes' , 'att_add_menu_id', 3, 10); | |
if ( !function_exists( 'att_add_menu_id') ) { | |
function att_add_menu_id($atts, $item, $args) { | |
if( 'page' == $item->object ){ | |
$id = $item->object_id; | |
$id = 'page-'. esc_attr( basename( get_permalink( $id ) ) ); | |
$atts['id'] = $id; | |
} | |
return $atts; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment