简体   繁体   中英

Wordpress - Custom Menu on Post pages

I would like to load a specific menu (that exists in Wordpress Menus) on pages that are "post".

Here is my current code (functions.php):

add_action('get_header', 'replace_post_menu');
function replace_post_menu() {
    if (is_singular('post')) {
        wp_nav_menu( array('menu' => 'New Menu' ));
    }
}

The problem is the menu is loading at the very top (above my current menu). I'm using the theme "Avada" (last version).

Could you help me?

If you want to load a specific menu in the posts and a common menu for all other pages, do the following.

1. Replace the below code with your code in header.php.

<?php
    if (! is_singular('post')) {
        wp_nav_menu( array('menu' => '{enter the name of your common menu here}' ));
    }
?>

2. Keep your existing code in functions.php.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM