S
S
Sergey Burduzha2018-06-06 13:55:07
WordPress
Sergey Burduzha, 2018-06-06 13:55:07

How to implement a custom menu in WordPress?

I have such a menu
5b17bce35d2ab588861682.jpeg
Here is the code of a single menu item
5b17bcf7f2ad3973351321.jpeg
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

1 answer(s)
S
Sergey Burduzha, 2018-06-06
@serii81

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;
}

In the menu, in the description field, I wrote the path to the image from the media files
. I had to change the layout a little, but I solved the problem without arbitrary post types and other methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question