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

WordPress error when creating custom menu

WBOY
Release: 2016-09-11 11:34:07
Original
1005 people have browsed it

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>
Copy after login
Copy after login

Step 2: page1.php

<code><?php wp_nav1_menu(); ?></code>
Copy after login
Copy after login

page2.php

<code><?php wp_nav2_menu(); ?></code>
Copy after login
Copy after login

page3.php

<code><?php wp_nav3_menu(); ?></code>
Copy after login
Copy after login

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>
Copy after login
Copy after login

Step 2: page1.php

<code><?php wp_nav1_menu(); ?></code>
Copy after login
Copy after login

page2.php

<code><?php wp_nav2_menu(); ?></code>
Copy after login
Copy after login

page3.php

<code><?php wp_nav3_menu(); ?></code>
Copy after login
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template