Home >Backend Development >PHP Tutorial >WordPress error when creating custom menu

WordPress error when creating custom menu

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-09-11 11:34:071036browse

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

Reply content:

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn