Someone posted a similar question in the Advanced WordPress facebook group. I suggested adding some token text to the menu item’s url and then swapping it out during render.
add_filter( 'nav_menu_link_attributes', 'dcwd_nav_menu_link_attributes', 10, 4 );
function dcwd_nav_menu_link_attributes( $atts, $item, $args, $depth ) {
// If PHONE_NUMBER is found then change it.
if ( false !== strpos( $atts[ 'href' ], 'PHONE_NUMBER' ) ) {
$atts[ 'href' ] = getPhone();
}
return $atts;
}
I also posted it to pastebin
Related Posts:
- Add settings to menu items in the Customizer
- Using string instead of object class instantiation on the walker argument breaks wp_nav_menu
- Remove ‘Menus’ from Twenty Sixteen theme Customizer
- Remove nav_menus from customizer using a theme
- Partial refresh of menu in customizer not working?
- Using Shortcodes in WP-Menus in WP 3.1 (via nav_menu_objects)?
- Navigation (wp_nav_menu) refuses to nest within parent element
- Different fields available for different sites when when customising Menu’s
- Using a shortcode to create a dropdown menu from wp_nav_menu list items
- Add media library items to Menus using the Customizer (via Media Manager not URL)
- How to customize submenus isn wordpress theme [closed]
- How to re-arrange the MENU of “Allure Real Estate Theme for Placester” wordpress theme?
- Can’t add a setting to the “nav_menus” customizer panel
- modify menu item links dynamically
- Can you add shortcode as a menu item link?
- Making the menu toggled open on mobile devices Illustratr theme
- Custom link with checkbox that adds additional word to checked menu items
- How to work with a custom theme that someone else created before me? (details below)
- WP Menu editor is hiding options for menu items
- WordPress Menu Customizer
- Iterate through each menu item into a shortcode
- Prevent Menu Shortcode From Formatting
- Problems with draft website pages
- Primary menu shortcode name
- Hiding Widget On Mobile Devices Removes Our Product Search Box On Mobiles
- Using a menu walker add a custom item at the end of the menu’s items
- Show current navigation path from menu
- Menu items (all menus) being deleted randomly on their own [duplicate]
- Put a wp_nav_menu inside another one
- different Menu position showing same menu
- How to add bubble count in WordPress wp_nav_menu menu?
- Add class to active top level (grandparent) menu item
- WordPress wp_nav_menu within iFrame
- Check if wp_nav_menu items have submenus
- wp_nav_menu doesn’t generate parent/ancestor classes
- WP_nav_menu fallback not working
- How to conditionally register nav menus with advanced custom fields?
- Use walker for specific menu, or avoid use of walker
- Change where navigation bar links?
- How to give custom classes to the WordPress Menu widget
- No “current-menu-ancestor” class added when browsing an archive page
- Does wp_nav_menu use the gettext filter?
- How to add #navbar to all page links?
- Problems Displaying Multiple WP Menus
- View h2 content tags of a page in sub menu
- How to add custom classes to more than one separate menu’s a link in wordpress?
- Change an li class name in a wordpress custom menu walker
- Custom walker nav – Add sequential number as class
- How to test if blog page is active
- WordPress Custom Menus Issue
- Side Menu Icon Expandable
- wordpress responsive menu not dropping down
- How to use a start_el variable in start_lvl
- Need Random Category Nav Menu
- edit user menu item
- Excluding a media query from specific pages
- Menu Arrow for Child Element
- Custom menu with different behavior for every item
- Responsive dropdown menu with smaller screen sizes
- Problem in applying active class to wordpress menu
- How to get submenu dropdown with images?
- Modifying the walker to insert parent’s description above sub menus
- wp_list_pages Hierarchical Help
- How to avoid the and which added when custon menu widget is used
- How to create a complete mulilanguage site using xili language plugin?
- An alternative to WordPress’s built-in menu functionality
- pre_get_posts fix to show menu on CPT Archives broken WP 6.0
- WordPress Menu Problem
- How to link current logged-in user to their author page via URL (Beginner)
- Top bar menus not showing on mobile
- Get Each Menu Nav Label of Menus in HTML tag
- Nav_walker add id to dropdown ul
- Navbar is hidden behind carousel when using wp-boostrap-navwalker
- WordPress nav-menus not finding page
- Primary menu items are dissapearing
- Active Current Menu – Adding class to child theme
- display cart information within li of cart menu item
- WPML CMS Nav and Custom Nav_Walker Undefined Property Notices [closed]
- Add data-track to links in menu
- How to add odd and even classes to all nav links through walker?
- Output sort number in wp menu list item?
- Check in walker if current page is descendant
- Add a non-dynamic phrase/character after a page title?
- Active page link not getting class assigned
- Removing menu item doesn’t get removed on edit post
- change link of menu particular tab
- Next page link via the custom menu
- Customize Walker_nav_menu to show posts if item is category
- Top menu link anchor href value change after online server?
- Menu not always using correct link
- How to handle change the appearance of ‘categories’ box on dashboard?
- How can I stop wp_nav_menu from returning extraneous root links?
- How to add posts with thumbnails to my dropdown menu?
- can anyone help me converting my static menu to wp_nav_menu I’am trying to add static menu item to WordPress Menu
- Change Menu Order
- Two Homes In Navigation Menu
- Theme supports only one menu. I need to add more – but how? [closed]
- Active Navigation Class Based on URL on icon
- Rename Menu icon in Twenty seventeen theme
- WordPress Menu – Adding a new dynamic element to the menu