All
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 ?
All
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 ?
You must be logged in to post a comment.
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:
You should modify the code:
has_log_out_link
for themenu_class
parameter onwp_nav_menu
and test$args->menu_class
.menu_item_parent
to a post ID other than0
if you need the link in a sub menu.In case someone else struggles with this, the easiest way I found was to simply add the Log out menu item exactly where you want it by using the custom link option. Make the url something unique like logouturl and the simply add this code to your functions.php file or wherever you prefer adding custom code.
Remember to change this first parameter of str_replace to the string used in the custom link of the menu settings. You might also need to change the theme_location from primary to the appropriate location.