복붙노트

[WORDPRESS] WordPress : 탐색 메뉴에 빈 목록 항목 추가

WORDPRESS

WordPress : 탐색 메뉴에 빈 목록 항목 추가

해결법


  1. 1.필터로 추가 할거야 :

    필터로 추가 할거야 :

    add_filter('wp_nav_menu_items', 'add_stretcher', 10, 2);
    function add_stretcher($items, $args) {
      if ($args->theme_location == 'primary') {
        $items .= '<li class="stretcher"></li>';
      }
      return $items;
    }
    

  2. 2.다음 코드가있는 jQuery를 사용하여 추가 할 수 있습니다

    다음 코드가있는 jQuery를 사용하여 추가 할 수 있습니다

    <script>
       jQuery(document).ready(function(){
          jQuery("#menu-primary li").last().before("<li class="stretcher"></li>");                             
       });
    </script>
    
  3. from https://stackoverflow.com/questions/18658643/wordpress-add-empty-list-item-to-navigation-menu by cc-by-sa and MIT license