Top Left Text cha

Web & App Development

Just an example function to add an 'instant logout' to the end of the menu...

function logout_menu_link( $items, $args ) {
if (($args->theme_location == 'main-menu') && (is_user_logged_in())) {
$items .= '<li><a href="'. wp_logout_url() .'">Logout</a></li>';
}
return $items;
}

Also, to put it somewhere other than the last item, here's another example...

function logout_menu_link( $items, $args ) {
{
if( $args->theme_location == 'main-menu' )
{
$new_item = array( '<li><a href="'. wp_logout_url() .'">Logout</a></li>' );
$items = preg_replace( '/<\/li>\s<li/', '</li>,<li', $items );

$array_items = explode( ',', $items );
array_splice( $array_items, 2, 0, $new_item ); // splice in at position 3
$items = implode( '', $array_items );
}
return $items;
}
}

Add comment


Security code
Refresh

  • No comments found

Leave your comments

Post comment as a guest

0
Your comments are subjected to administrator's moderation.
X