Time to nerd out with some code!

There was a great request on the WordPress.org Plugin Repository support forum to add a “logout” link to the Kanban board’s settings menu.

We’d thought about this previously, but hesitate to clutter up the settings menu. So this is a great opportunity to take advantage of WordPress’ famous hooks and filters!

logout on settings menu

Kanban for WordPress has lots of hooks and filters throughout. To add a new menu item, we’ll take advantage of the kanban_page_footer_menu_dropup filter.

Here’s the complete code (I’ll explain it below). Add it to your themes functions.php, and you will now see a logout link on the setting menu.

add_filter (
 'kanban_page_footer_menu_dropup',
 'add_logout_to_settings_menu'
);

function add_logout_to_settings_menu ($html)
{
    $li = '<li><a href="' . wp_logout_url() . '">' .  __('Logout') . '</a></li>';
    return $html . $li;
}

First, we add our filter, and link to a custom function called add_logout_to_settings_menu.

This filter receives any previously added menu items. We’ll want to add our new item to the html, and return it.

Menu items are simple <li> tags with <a> link. We want to use WordPress’ native logout url function. So we combine these two into a string, append it to the passed html and return it.

Leave a Reply

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