简体   繁体   English

WordPress-帖子页面上的自定义菜单

[英]Wordpress - Custom Menu on Post pages

I would like to load a specific menu (that exists in Wordpress Menus) on pages that are "post". 我想在“发布”页面上加载特定菜单(存在于Wordpress菜单中)。

Here is my current code (functions.php): 这是我当前的代码(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). 我使用的主题是“ Avada”(最新版本)。

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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