0

I want to add a logo to my main menu. I am using this function:

add_filter( 'wp_nav_menu_items', 'add_logo_to_menu_item', 10, 2 );
function add_logo_to_menu_item ( $items, $args ) {
    if ($args->menu == 'main-menu') {
        $items .= '<li><a href="#"><img src="PATH_TO_IMAGE"></a></li>';
    }

    return $items;
}

The problem I am having is I want the logo to be at the top of the menu. This filter currently places it in the last position of the menu. Any ideas?

3

Use $items = 'Blah'.$items instead of $items .= 'Blah'

add_filter( 'wp_nav_menu_items', 'add_logo_to_menu_item', 10, 2 );

function add_logo_to_menu_item ( $items, $args ) {

    if ($args->menu == 'main-menu') {
        $items = '<li><a href="#"><img src="PATH_TO_IMAGE"></a></li>' . $items;
    }

    return $items;

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.