0

Данный код выводит изображение рядом с ссылкой, а необходимо внутрь ссылки:

add_filter( 'walker_nav_menu_start_el', 'filter_walker_nav_menu_start_el', 10, 4 );
function filter_walker_nav_menu_start_el( $item_output, $item, $depth, $args ) {
  if ( ! empty( $item->classes ) && in_array( 'menu-item-has-children', $item->classes ) ) {
    $item_output .= '<img src="'. get_template_directory_uri() .'/assets/images/icon.svg" alt="">';
  }

  return $item_output;
}

1 ответ 1

0

Вот так https://wp-kama.ru/hook/nav_menu_item_title

add_filter('nav_menu_item_title', 'filter_nav_menu_item_title', 10, 4);
function filter_nav_menu_item_title($title, $item, $args, $depth)
{
    $title = '<img src="' . get_template_directory_uri() . '/assets/images/icon.svg" alt="">' . $title;

    return $title;
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.