WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


I am using wordpress custom menu, and there is one menu as Logout. I know wordpress Logout function <?php echo wp_logout_url(); ?>

But how can i use it in custom menu ?

share|improve this question
up vote 6 down vote accepted

Not sure how and where you can create a custom button, but you can add such a link per filter: Add a filter function to 'wp_nav_menu_objects' and insert the link where you need it.

Here is a basic example:

add_filter( 'wp_nav_menu_objects', 'wpse_46547_add_log_out_link', 10, 2 );

function wpse_46547_add_log_out_link( $sorted_menu_items, $args )
    $link = array (
        'title'            => 'Log out',
        'menu_item_parent' => 0,
        'ID'               => '',
        'db_id'            => '',
        'url'              => wp_logout_url()

    $sorted_menu_items[] = (object) $link;

    return $sorted_menu_items;

You should modify the code:

  • Check if you are on the correct menu. For example require a class has_log_out_link for the menu_class parameter on wp_nav_menu and test $args->menu_class.
  • I18n for the menu title. ;)
  • Set menu_item_parent to a post ID other than 0 if you need the link in a sub menu.
  • There are more parameters for the link, see my other answer to inspect those.
share|improve this answer
I have side bar in there, there are custom menu, i have added there pages & category. But last menu is Logout, When user click on logout menu, i want to logout that user. – Ajay Patel Mar 23 '12 at 7:19
Yes, I understood this. Create an item, add it to the custom menu, and you are done. – toscho Mar 23 '12 at 7:27
Okay Thanks ... – Ajay Patel Mar 23 '12 at 7:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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