Wordpress Themes - WP Forum at BFA
Click here to register or to donate.
Auto self-registration is not available here - far too many spammers. This forum has many, many backlinks and because of that there is an intense desire among spammers to drop their links here.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Montezuma Theme »

Inserting logout link into Montezuma

Old Apr 16, 2016, 11:57 PM
flyboy's Avatar
115 posts · Sep 2010
I wish to add logout link into the header, but I'm having problems:

1. Adding <a href="/wp-login.php?action=logout">Logout</a> redirects to a page asking to confirm logging out (undesired)
2. Adding the usual <a href="<?php echo wp_logout_url(); ?>">Logout</a> into header subtemplate doesn't output the actual logout link

I know that I could create a widget and use that to output the logout link, but that feels a bit like joining the marines just to learn to fold the underwear.

Any idea how to create a simple logout link? Is it possible to create an extra php file and call it from a subtemplate or something like that? If so, what would be the steps?
Old Apr 17, 2016, 02:20 AM
CrouchingBruin's Avatar
299 posts · Aug 2010
Santa Monica, CA
I don't remember where I got this code snippet from, but it adds a logout menu item to the end of the menu. What I like about it is that the logout link becomes part of the menu, instead of a separate link.
// Add logout menu item
function add_login_logout_link($items, $args)
  $newitems = $items;
  $newitems .= '<li><a title="Logout" href="'. wp_logout_url('index.php') .'">Logout</a></li>';
  return $newitems;
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
I add it using the Header and Footer plugin, which allows you to add PHP code or Javascript to all pages.
My Montezuma-themed sites: ESHS Girls Basketball Team, Venice Hongwanji Buddhist Temple
Please consider making a donation to BytesForAll for their great themes!
Old Apr 17, 2016, 03:20 AM
flyboy's Avatar
115 posts · Sep 2010
Thanks, I saw that in one of the discussion on Wordpress.org too, but sadly the design requirements are for a logout link outside the menu (essentially in a custom created div that site at the very top of the site).

Could this be done by calling an external php file somehow?
Old Apr 17, 2016, 07:38 PM
juggledad's Avatar
23,759 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
Try this, add the following to the end of function.php
HTML Code:
//Logout Shortcode
function logout_func ($atts, $content = null) {
		'linktext' => 'Log Out',
		), $atts));
	$logoutlink = wp_logout_url( home_url() );
	 return '<a href="' . $logoutlink . '" title="Logout">'. $linktext .'</a>';
add_shortcode( 'wplogout', 'logout_func' );
go to MTO->Sub Templates->Header.php and add the folowing where ever you want
HTML Code:
<?php echo do_shortcode('[wplogout linktext="Logout"]'); ?>
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
Old Apr 19, 2016, 01:15 PM
flyboy's Avatar
115 posts · Sep 2010
Thank you JD, you da man, as always.
Side note, sent you a PM regarding something unrelated a few days ago =)



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Logout error bug sober Atahualpa 3 Wordpress theme 2 Jan 5, 2011 06:11 AM
Logout link in footer fails in WP2.7 BradBrown Atahualpa 3 Wordpress theme 3 May 24, 2009 05:10 PM
WP-admin logout/in for changes to occur? Craig Mattice Atahualpa 3 Wordpress theme 2 Apr 30, 2009 04:26 PM
Settings Not Saving Until Logout ieatgravel Atahualpa 3 Wordpress theme 3 Apr 14, 2009 06:25 AM

All times are GMT -6. The time now is 12:49 PM.

Powered by vBulletin® Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.