How to add a custom item to a specific WordPress menu item position

后端 未结 4 1396
北荒
北荒 2020-12-30 16:48

I have a primary menu registered and displayed that consists of 4 links (home, about, news, blog). I want to add html (a logo) in between the second and third menu and I was

4条回答
  •  一个人的身影
    2020-12-30 17:29

    Little variation on Compass' solution, getting rid of the loop.

    add_filter('wp_nav_menu_items','add_custom_in_menu', 10, 2);
    
    // add in Logo in the middle of the menu
    //
    function add_custom_in_menu( $items, $args )
    {
        if( $args->theme_location == 'footer_navigation' )
        {
            $new_item       = array( '' );
            $items          = preg_replace( '/<\/li>\s
  • ,
  • Not sure if it will be much fast using build in functions. Your choice

提交回复
热议问题