Answer the question
In order to leave comments, you need to log in
How to implement a custom menu in WordPress?
I have such a menu
Here is the code of a single menu item
First I thought to make a menu heading where one entry would be a menu item with a picture and a link.
The problem is how to correctly write a link for each menu item?
If done in a standard way, then how to add a picture for the menu? And the code doesn't match ul with li.
Here is a link to the site test.webforworld.info/Transcargo
This is not a working project, but the first educational one.
What do you advise?
Answer the question
In order to leave comments, you need to log in
Solved the problem in the following way
add_filter( 'nav_menu_link_attributes', 'filter_function_name_3020', 10, 4 );
function filter_function_name_3020( $atts, $item, $args, $depth ){
$img = $item->description;
$link = $atts['href'];
if ( $args->theme_location == 'index-menu' ) {
$args->link_before = '
<div class="main-item">
<div class="img-wrap">
<a href="'.$link.'">
<div class="img-inner">
<img src="'.$img.'" alt="img">
</div>
</a>
</div>
<h3 class="main-title">';
$args->link_after = '</h3>
<a href="'.$link.'" class="home-button button-red">View Page</a>';
}
return $atts;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question