Support

Account

Home Forums ACF PRO Menu enhancement for WordPress

Solving

Menu enhancement for WordPress

  • Hello,

    Would anyone know if there’s a combination of an Acf function or field that helps me set up the following.

    I’d like to create a menu in WordPress and use the is_page conditional to navigate the user to a specific page depending on the page they are on.

    So I have 1 standard WP menu created, and one of the link buttons is “Size”. But rather than drag an item from the left pane which allows only one destination for a button I would ideally use an enhanced setup.

    For example if the user is on Page 2162 and they click the button they are taken to ‘page A’, but if they are on page 1593 the button takes them to ‘page B’ etc. This method would allow 1 menu to be created and managed.. I can’t see how it could be possible to create separate menus for each of the many linked scenarios (maybe if the Navigation Labels could be globally updated etc?)

    Would I place the code shown in link below in my themes functions and work from here, adding all the code to my pages in?

    https://developer.wordpress.org/reference/functions/is_page/

    thanks!

  • This is not something that ACF will do. This is something that you’d use the hook wp_nav_menu_items and wp_nav_menu_objects to do. The references are here https://developer.wordpress.org/reference/hooks/wp_nav_menu_items/ and here https://developer.wordpress.org/reference/hooks/wp_nav_menu_objects/. During this filter is where you’d need to alter the links to each menu item.

    I couldn’t begin to tell you how to tell what page the link should be to, you could maybe add a link to each page to tell what page should be linked to, but I don’t know what information you can get on each page or how you would get the ACF values for a page based on the link value.

    There is an explanation of how to use ACF fields in a menu here https://www.advancedcustomfields.com/resources/adding-fields-menus/ and here https://www.advancedcustomfields.com/resources/adding-fields-menu-items/, but this is based on adding custom values to the menu and not to the page.

    Basically, you’d need to get the current page id if it is available when the menu is created, I do not know if is_page() will work here. Then you’d need to get the link value from the page. And finally replace the link that’s generated with your new html code for the alternate link. You could add a custom field to each menu item? checkbox maybe? Then if the checkbox is checked you might be able to set the url?

    Sorry I couldn’t be more help. I have not had the opportunity to use the new menu location features of ACF so I’m only able to provide a direction to look.

  • Thanks John that’s great and concise and will check out the info on those links. Its reassuring to know that WordPress platform is structured to accommodate this and it’s now a matter of nutting it out.

    This has also confirmed that a developer could be required to achieve the menu setup but I will be well informed at a minimum. May repost here soon but reading the above will take a while for me to absorb.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Menu enhancement for WordPress’ is closed to new replies.