为WordPress主题添加设置菜单位置提示

Kevin 杂记 868 次浏览 25条评论

制作WordPress主题的一个小细节。如果用户没创建菜单或设置菜单位置,主题导航菜单处默认只显示首页和单页链接,其HTML结构还可能影响显示效果。为了改善这方面的体验,有个简单解决方法,在菜单函数里添加fallback_cb参数解决,以下是操作方法,做个记录。

1. 找到wp_nav_menu菜单函数,按下面示例添加fallback_cb参数。通常在header.php文件里。

<?php wp_nav_menu( array( 'fallback_cb' => 'primary_menu_fallback_cb', 'container' => false, 'items_wrap' => '<ul>%3$s</ul>', 'theme_location' => 'primary' ) ); ?>

2. 打开主题functions.php文件,添加菜单设置提示内容,当用户没设置菜单时就会显示提醒。

/**
 * 提示设置主菜单
 */
function primary_menu_fallback_cb() {
 echo '<ul><li><a href="' . admin_url( 'nav-menus.php' ) . '">Set Primary Menu</a></li></ul>' ."\n";
}

3. 设置完成。这个方法比较简单,还可以有其它改进,比如改善默认菜单内容输出。不过这也够用了,问题场景不常遇到。

评论列表

  1. #1

    Hi, very nice website, cheers!
    ——————————————————
    Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo.
    ——————————————————
    Check here: https://www.reliable-webhosting.com/

  2. #2

    6000 doctors prescribing hydroxychloroquine https://hydroxychloroquine.webbfenix.com/

  3. #3

    acyclovir vs famciclovir vs valacyclovir https://www.herpessymptomsinmen.org/productacyclovir/

  4. #4

    ivermectin doses human https://ivermectin.webbfenix.com/

  5. #5

    fda approved generic vidalista https://vidalista.mlsmalta.com/

  6. #6

    is revatio and dapoxetine interchangeable https://salemeds24.wixsite.com/dapoxetine

  7. #7

    reviews torrent pharmaceuticals silagra https://silagra.buszcentrum.com/

  8. #8

    average cost of viagra pills http://droga5.net/

  9. #9

    hydroxychloroquine use for fibromyalgia https://hydroxychloroquine.mlsmalta.com/

  10. #10

    merck ivermectin https://ivermectin.mlsmalta.com/

  11. #11

    generic viagra vs vidalista https://vidalista40mg.mlsmalta.com/

  12. #12

    online rx meds reviews https://medpills.bee-rich.com/

  13. #13

    cialis viagra levitra trial pack https://wisig.org/

  14. #14

    albuterol sulfate inhalation aerosol hfa https://amstyles.com/

  15. #15

    lowest price for priligy 60 mg https://ddapoxetine.com/

  16. #16

    chloroquine stock price https://hydroxychloroquinee.com/

  17. #17

    generic cialis online https://www.lm360.us/

  18. #18

    I’ve been surfing on-line more than three hours as of late, yet I by no means discovered any fascinating article like yours. It’s pretty value enough for me. In my opinion, if all site owners and bloggers made good content as you probably did, the web will likely be much more useful than ever before. “When the heart speaks, the mind finds it indecent to object.” by Milan Kundera.

    http://www.vreyrolinomit.com/

  19. #19

    find a doctor who will prescribe hydroxychloroquine https://hydroxychloroquine.grassfed.us/

  20. #20

    cialis dose for ed https://cialis.mrdgeography.com/

  21. #21

    cialis dose for ed https://cialis.stdstory.com/

  22. #22

    Greate pieces. Keep writing such kind of information on your blog.
    Im really impressed by your site.
    Hey there, You’ve done an incredible job. I’ll certainly digg it and
    individually recommend to my friends. I’m sure they’ll be benefited
    from this website. http://antiibioticsland.com/Amoxil.htm

  23. #23

    You mentioned it exceptionally well!. https://kamagrajellynow.com

  24. #24

    Whoa a lot of helpful advice. https://www.goldkamagra.com kamagra 800mg Ajktc89

  25. #25

    buy viagra

发表评论

电邮地址用于 Gravatar 头像显示,不会被公开可见。