How to register a menu based on a ACF condition

Ok, so the problem was that I was adding the variable outside the function. After some cleanup, code looks like this and it works! function roots_setup() { // Variables $header_type = get_field(‘header_type’,’options’); if (($header_type)==’brand-centered’) { register_nav_menus(array( ‘brand_centered_left’ => __(‘Brand Centered Navigation (Left)’, ‘roots’) )); register_nav_menus(array( ‘brand_centered_right’ => __(‘Brand Centered Navigation (Right)’, ‘roots’) )); } else … Read more

wp_nav_menu work in functions.php but not in the theme

I had a pre_get_posts. What I missed was this: && $wp_query->is_main_query() This prevents the pre_get_posts to run on the menu query. Full code add_action(“pre_get_posts”, “custom_front_page”); function custom_front_page( $wp_query ){ if( is_admin() ) { return; } if( is_front_page() && $wp_query->is_main_query() ) { $wp_query->set(‘post_type’, ‘produkt’); $wp_query->set(‘page_id’, ”); $wp_query->is_page = 0; $wp_query->is_singular = 0; $wp_query->is_post_type_archive = 1; $wp_query->is_archive … Read more

New Menu Item Type Meta Box

Yes, this should certainly be possible, although as you have noticed it’s not too common. If you take a look at respective admin template the left column is built like this: <?php do_accordion_sections( ‘nav-menus’, ‘side’, null ); ?> Essentially they are just metaboxes, though differently presented. The defaults are handled by wp_nav_menu_setup(), which should be … Read more

If test for “has_nav_menu()” does not return echo when no menu exists

If you check out has_nav_menu(), you’ll see that it first checks if a menu exists for the location (what we expect). However, it will also return true if the location is merely registered, hence why your condition is still true even when there’s no menu: function has_nav_menu( $location ) { $registered_nav_menus = get_registered_nav_menus(); if ( … Read more

Menu deletes all items and position – wordpress bug?

I think this is a bad case of taxonomy split introduced in WP 4.2 ref. https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/ Solution for this would be to use this plugin to detect and fix the splitting before Updating menus which is a bit buggy in my opinion. Update nav menus will trigger “wp_nav_menu_update_menu_items” function which between split gives new menu … Read more

Menu page with three columns

I would avoid any core-related layout classes and just roll your own (you don’t need bootstrap for this). In your PHP page handler, just kick out something like: <div class=”wrap”> <div class=”my-plugin-column”> How… </div> <div class=”my-plugin-column”> you… </div> <div class=”my-plugin-column”> doin’? </div> <!– And so forth –> </div> And then in your plugin CSS: @media … Read more

How can I query all available public post types and taxonomies?

There are several ways to answer that question, depending on what it is you are attempting to accomplish. To generalize, you need to create two queries: one to get all public posts and one to get all public taxonomies and terms. Getting both in one array is not practical as term objects and post objects … Read more