New answers tagged

1

There are a few ways to do this and they mostly revolve around the walker_nav_menu_start_el filter. I'd be inclined to add custom fields to the nav menu items: one for the image and one for the image's alternate text. That way, users can update the images and developers aren't required to keep a hash of all menu items and related image URLs/alt text in code ...


2

Please Try with bellow : wp_nav_menu( array( 'theme_location' => 'header_menu', 'container_id' => 'menu', 'walker' => new description_walker() ) ); And Add functions.php class description_walker extends Walker_Nav_Menu{ function start_el(&$output, $item, $depth, $args){ global $wp_query; $indent = ( $depth ) ? ...


2

Solution 1: Using customize walker I got some idea from add span class inside wp_nav_menu link anchor tag and make some change as your requirement. 1. Add this code below to your functions.php first. class Nav_Walker_Nav_Menu extends Walker_Nav_Menu{ function start_el(&$output, $item, $depth, $args){ global $wp_query; $indent = ( ...


0

You can use the wp_nav_menu() arguments like so: wp_nav_menu( array( 'menu' => 'Whatever Your Menu Name Is', 'link_before' => '<span class="main-nav__item-icon-wrapper"><i class="main-nav__item-icon icon-home"></i></span><span class="main-nav__item-content">', 'link_after' => '</span>' ) ...


2

If you are trying to get the post type for the current 'post', I think you could go with get_post_type(). Like this: $post_type = get_post_type(); Try it out.


0

To add a new attribute to your anchor link for the nav items concatenate $attribute variable with your required attribute. You have commended code just uncomment the code and use those $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_atta( $item->attr_title ) .'"' : ''; $attributes .= ! empty( $item->target ) ? ' ...


-1

The change to be done is to change: $item_output .= '<a'. $attributes .'>'; to $item_output .= '<a itemprop=url'. $attributes .'>';



Top 50 recent answers are included