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

时间:2014-08-06 18:41:15

标签: php wordpress

我想在“发布”的页面上加载特定菜单(存在于Wordpress菜单中)。

这是我当前的代码(functions.php):

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

问题是菜单正在顶部加载(在我当前的菜单上方)。我使用的主题是“Avada”(最新版本)。

你能帮帮我吗?

1 个答案:

答案 0 :(得分:1)

如果您要在帖子中加载特定菜单,并为所有其他页面加载常用菜单,请执行以下操作。

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.