Support

Account

Home Forums ACF PRO Is it possible to create a custom field to hold a menu widget?

Solved

Is it possible to create a custom field to hold a menu widget?

  • I need to add a custom field to certain Pages, and in that custom field to be able to select from the Menus that have been created, similar to how one selects a Menu in a Widget that is dragged to a Widget Area. The Menu could be different depending on which Page is displayed.

    That way if the Menus are updated under Appearance>Menus I don’t have to go back to all of those Pages and update them there as well.

    If someone knows how to do this, OR if there is an easier way to allow a User to select a specific Menu to be displayed on some pages after the content I would welcome all suggestions!

  • There are several nav menu fields, but none have been updated in some time and I don’t know if they will still work. You can do a search here for “menu” to find them https://www.awesomeacf.com/.

    I have done this in the past by using a simple select field and populating the select field https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/ using wp_get_nav_menus https://developer.wordpress.org/reference/functions/wp_get_nav_menus/. Then on the front end template calling wp_nav_menu() https://developer.wordpress.org/reference/functions/wp_nav_menu/ to show the menu.

  • Thank you John, excellent suggestion! I have done some dynamic population of select fields so that would not be too hard to implement, I guess I hadn’t thought of that because I’d only ever done it with Posts, not menus, but it makes sense that it would work the same way.

    In the interim I have created templates for each page that does call the menu using wp_nav_menu(), but I’d like to reduce the number of templates needed overall and make it more user-friendly, so I like your solution much better than mine!

    I’ll give this a try later today and will post back my final solution and code examples in case others need to do something similar.

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

You must be logged in to reply to this topic.