芝麻web文件管理V1.00
编辑当前文件:/home/r5772835/public_html/blog.ycreate.jp/wp-content/themes/swell/lib/custom_menu.php
__( 'グローバルナビ', 'swell' ), 'sp_head_menu' => __( 'スマホ用ヘッダー', 'swell' ), 'nav_sp_menu' => __( 'スマホ開閉メニュー内', 'swell' ), 'footer_menu' => __( 'フッター', 'swell' ), 'fix_bottom_menu' => __( '固定フッター(SP)', 'swell' ), 'pickup_banner' => __( 'ピックアップバナー', 'swell' ), ] ); } /** * liタグのIDを削除する */ add_filter( 'nav_menu_item_id', __NAMESPACE__ . '\hook_nav_menu_item_id', 10, 3 ); function hook_nav_menu_item_id( $menu_id, $item, $args ) { $noid_locations = [ 'header_menu', 'sp_head_menu', 'nav_sp_menu', 'footer_menu', 'fix_bottom_menu', 'pickup_banner', ]; if ( in_array( $args->theme_location, $noid_locations, true ) ) { return ''; } return $menu_id; } /** * liに付与されるクラスをカスタマイズ */ add_filter( 'nav_menu_css_class', __NAMESPACE__ . '\hook_nav_menu_css_class', 10, 3 ); function hook_nav_menu_css_class( $classes, $item, $args ) { $location = $args->theme_location; if ( 'sp_head_menu' === $location ) { $classes[] = 'swiper-slide'; } elseif ( 'pickup_banner' === $location ) { $classes[] = 'p-pickupBanners__item'; } return $classes; } /** * リストのHTMLを組み替える * 例:「説明」を追加(ナビゲーションの英語テキストに使用) */ add_filter( 'walker_nav_menu_start_el', __NAMESPACE__ . '\hook_walker_nav_menu_start_el', 10, 4 ); function hook_walker_nav_menu_start_el( $item_output, $item, $depth, $args ) { // 特定のメニューに対して処理 $menu_location = $args->theme_location; if ( $menu_location === 'header_menu' || $menu_location === 'nav_sp_menu' ) { if ( ! empty( $item->description ) ) { // desc はしばらく残す $item_output = str_replace( '', '
' . $item->description . '
', $item_output ); } if ( SWELL::is_use( 'acc_submenu' ) && in_array( 'menu-item-has-children', $item->classes, true ) ) { $item_output = str_replace( '', '
', $item_output ); } } elseif ( $menu_location === 'fix_bottom_menu' ) { // 固定フッターメニュー $target = ( $item->target === '_blank' ) ? ' target="_blank" rel="noopener noreferrer"' : ''; $item_output = '
' . '
' . $item->title . '
' . '
'; } elseif ( $menu_location === 'pickup_banner' ) { // ピックアップバナー $item_output = SWELL::get_pluggable_parts( 'pickup_banner', [ 'item' => $item, 'menu_count' => $args->menu->count, ] ); } elseif ( $menu_location === '' ) { if ( SWELL::is_use( 'acc_submenu' ) && in_array( 'menu-item-has-children', $item->classes, true ) ) { $span = '
'; $item_output = str_replace( '', $span . '', $item_output ); } } // icon 使えるように $item_output = do_shortcode( $item_output ); return $item_output; }