简体   繁体   English

创世纪条件挂钩不起作用我在做什么错?

[英]Genesis Conditional Hooks Not working What am I doing wrong?

So I am trying to call the genesis_do_nav hook so its only on the front page and the homepage. 因此,我试图将genesis_do_nav挂钩命名为仅在首页和首页上使用。 For some reason it doesn't work unless I do 由于某种原因,除非我这样做,否则它不起作用

add_action( 'genesis_entry_header', 'genesis_do_nav' ); add_action('genesis_entry_header','genesis_do_nav');

But that is going to execute the menu on the entry header globally which is exactly what I am trying to avoid. 但这将全局执行条目标题上的菜单,这正是我要避免的。 Any suggestions 有什么建议么

 remove_action( 'genesis_after_header', 'genesis_do_nav' );
    add_action( 'genesis_entry_header', 'menu_only_on_homepage' );

    function menu_only_on_homepage() {

        if( is_home() && is_front_page() ){
                genesis_do_nav();
            }
    }

Two Ideas I would like you to try: 我希望您尝试以下两种方法:

A. First Issue I see is with your condition ie is_home() && is_front_page() I think this condition will never be true as both are different pages. is_home() && is_front_page() 我看到的第一个问题与您的条件有关,is_home() && is_front_page()我认为这种条件永远不会成立,因为两者都是不同的页面。 So maybe you wanted to have it is_home() || is_front_page() 所以也许您想拥有它is_home() || is_front_page() is_home() || is_front_page()

B. Try Re Arranging the code , Try arranging your conditional in different order so that you have condition before you add the hook ie B. 尝试重新安排代码 ,尝试以不同顺序安排条件,以便在添加钩子之前有条件,即

    if(is_home() || is_front_page() ){
        add_action( 'genesis_entry_header', 'genesis_do_nav' );
        }

See if it helps in your situation please note code is untested as I wrote here so first test it on dev environment before trying on live so you could easily fix any typos or syntax errors. 看看它是否对您有帮助,请注意,我在这里编写的代码未经测试,因此请先在开发环境中对其进行测试,然后再进行实时尝试,以便您轻松修复任何错字或语法错误。

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

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