I want to add a custom menu to WordPress
Method:
Step 1: functions.php
<code>if (function_exists('register_nav_menus')){ register_nav_menus( array( 'nav1' => __('网站导航1'), 'nav2' => __('网站导航2'), 'nav3' => __('网站导航3'), )); } function wp_nav1_menu($class='nav1', $location='nav1'){ echo '<ul class="'.$class.'">'.str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'</ul>'; } function wp_nav2_menu($class='nav2', $location='nav2'){ echo '<ul class="'.$class.'">'.str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'</ul>'; } function wp_nav3_menu($class='nav3', $location='nav3'){ echo '<ul class="'.$class.'">'.str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'</ul>'; }</code>
Step 2: page1.php
<code><?php wp_nav1_menu(); ?></code>
page2.php
<code><?php wp_nav2_menu(); ?></code>
page3.php
<code><?php wp_nav3_menu(); ?></code>
Step 3: Enter the management background to set the corresponding menu, and the front desk will display normally (the menu is created)
Problem:
When I followed the above steps to create nav4 on the page4.php page, the page error occurred:
Fatal error: Call to undefined function wp_nav4_menu() in /……/page4.php on line x
I want to add a custom menu to WordPress
Method:
Step 1: functions.php
<code>if (function_exists('register_nav_menus')){ register_nav_menus( array( 'nav1' => __('网站导航1'), 'nav2' => __('网站导航2'), 'nav3' => __('网站导航3'), )); } function wp_nav1_menu($class='nav1', $location='nav1'){ echo '<ul class="'.$class.'">'.str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'</ul>'; } function wp_nav2_menu($class='nav2', $location='nav2'){ echo '<ul class="'.$class.'">'.str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'</ul>'; } function wp_nav3_menu($class='nav3', $location='nav3'){ echo '<ul class="'.$class.'">'.str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'</ul>'; }</code>
Step 2: page1.php
<code><?php wp_nav1_menu(); ?></code>
page2.php
<code><?php wp_nav2_menu(); ?></code>
page3.php
<code><?php wp_nav3_menu(); ?></code>
Step 3: Enter the management background to set the corresponding menu, and the front desk will display normally (the menu is created)
Problem:
When I followed the above steps to create nav4 on the page4.php page, the page error occurred:
Fatal error: Call to undefined function wp_nav4_menu() in /……/page4.php on line x