On installing and activating the plugin, the plugin causes PHP warnings on deprecated functions:
Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /project/wordpress/wp-includes/functions.php on line 7288
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /project/wordpress/wp-includes/functions.php on line 2187
Here is an example. I had a situation where I needed to use different menus based on the page (not my idea!). So I added a Menu ACF field to the page post type. I used the Menu ID as what would be returned.
In my functions file I registered my menus
<?php
register_nav_menus( array(
‘primary’ => __( ‘Main Menu Live’, ‘main-menu’ ),
‘primaryvirtual’ => __( ‘Main Menu Virtual’, ‘main-menu-virtual’ ),
‘naemea’ => __( ‘North America and EMEA Menu’, ‘naemea-menu’ ),
‘apac’ => __( ‘APAC Menu’, ‘apac-menu’ )
) );
?>
In the header.php file of my theme I then dynamically call the menu.
<?php
if (class_exists(‘ACF’)) {
$main_menu= get_field(‘main_menu’, get_the_ID());
}
$theme_location = ‘primary’;
switch ($main_menu) {
case 3:
$theme_location = ‘primary’;
break;
case 7:
$theme_location = ‘naemea-menu’;
break;
case 8:
$theme_location = ‘apac-menu’;
break;
default:
$theme_location = ‘primary’;
}
?>
Then change the wp_nav_menu this way.
<?php
wp_nav_menu(array(
‘menu’ => $main_menu,
‘theme_location’ => $theme_location,
‘depth’ => 3,
‘container’ => ‘div’,
‘container_class’ => ‘collapse navbar-collapse’,
‘container_id’ => ‘bs-navbar-collapse-1’,
‘menu_class’ => ‘nav navbar-nav menu-main-menu’,
‘fallback_cb’ => ‘WP_Bootstrap_Navwalker::fallback’,
‘walker’ => new WP_Bootstrap_Navwalker(),
));
?>
Hope that helps those lost in the WordPress php world.
]]>How do i use this in the template?
What code do i have to add to show the menu i selected?
Regards
Hi,
Thank for you plugin, it works like a charm. I’m just uncomfortable using the hook to alter the generated html… Could you please being more specific more hooks beginners like me? I’m trying to get a minimal html output like:
<div class="main-menu">
<ul>
<li>
</ul
</div>
Thanks by advance
]]>