Skip to content

Instantly share code, notes, and snippets.

@lloc
Created August 15, 2013 13:37
Show Gist options
  • Select an option

  • Save lloc/6240884 to your computer and use it in GitHub Desktop.

Select an option

Save lloc/6240884 to your computer and use it in GitHub Desktop.
Add existing nav-menus to an select created by the "Advanced Custom Fields"-plugin #WordPress #ACF
<?php
namespace WPSE\realloc;
function my_site_menu( $field ) {
$field['choices'] = array();
$menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
if ( is_array( $menus ) ) {
foreach( $menus as $menu ) {
$field['choices'][$menu->name] = $menu->name;
}
}
return $field;
}
add_filter( 'acf/load_field/name=nav_menu', __NAMESPACE__ . '\\my_site_menu' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment