Friday , December 20 2024

How to add any text at the end of the menu in WordPress

Now many templates include menus with 100 percent width, and then there is a case – for example, place icons on the right, or insert contacts for mobile devices in the opening menu block. There is a function to implement:

add_filter( 'wp_nav_menu_items', 'my_custom_menu_block', 10, 2 );
function my_custom_menu_block ( $items, $args ) {
    if ($args->theme_location == 'main_menu') {
        $items .= '<li>custom text or html code</li>';
    }
    return $items;
}

This code should be placed at the end of the functions.php file of the site template.
Instead of main_menu, you need to specify the ID of the menu that needs additional code at the end.

About admin

Hi there! My name is Iryna, I am a web developer from Ukraine. While working on freelance projects I often face different technical issues and in this blog I publish articles on how to solve them. I am also interested in digital drawing and in this blog you will find brief tutorials that helped me and hopefully can help you as well.

Check Also

How to remove 404 //fonts.gstatic.com and //fonts.googleapis.com from WordPress head section

I tried solutions with functions that should remove from head and , but a very …

Leave a Reply

Your email address will not be published. Required fields are marked *