Iterate through each menu item into a shortcode

Skimming through the core file, there are some quick & dirty ways available (untested):

  • ! is_admin() && add_filter( 'wp_nav_menu_items', 'do_shortcode' );

  • ! is_admin() && add_filter( 'the_title', 'do_shortcode' );

  • ! is_admin() && add_filter( 'walker_nav_menu_start_el', 'do_shortcode' );

But I would rather target the menu labels directly with for example (untested):

/**
 * Support shortcodes in the menu labels
 */
! is_admin() && add_action( 'nav_menu_link_attributes', 'wpse_shortcode_in_menu' );

function wpse_shortcode_in_menu( $atts )
{
    add_filter( 'the_title', 'wpse_do_shortcode' );
    return $atts;
}

function wpse_do_shortcode( $content )
{
    remove_filter( current_filter(), __FUNCTION__ );
    return do_shortcode( $content );
}