I want to add a logout button on the side admin menu (because I disable the admin bar for the users). So I thought add_menu_page() is the way to do it, but how to add the link to the regarded function?
Here is what i did:
add_action( 'admin_menu', 'my_logout_menu' );
function my_logout_menu() {
add_menu_page( 'Logout', 'Logout', 'read', 'logout', 'my_logout' );}
function my_logout() {
echo wp_logout_url( $redirect );}//here is I don't know what to do.
Am I using the correct approach? or there are other easier ways to do it?
I’m using this as a custom logout button, it also displays a random quote before logout the user. I think you can adapt it to your needs by removing what you don’t need.
Instructions:
Copy the code below and save as users-logout.php
Create a folder called users-logout, upload the file and the images below to work.
Any problems just let me know
Images:
Code:
If you’re removing the toolbar, then you’re not using the correct approach in the first place. The toolbar is more than just an admin menu for users to log out with …
As for your code … no, this won’t work.
add_menu_page()
adds a link to a specific page represented by a function in WordPress. You’re trying to add a page that has nothing on it but a link to log out with.The
add_menu_page()
function isn’t really meant for adding links to the menu. Check out this answer. Your final code will be something like this (though this snippet is untested):+1 to @EAMann’s point about not removing the toolbar, though.