Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Montezuma Theme (http://forum.bytesforall.com/forumdisplay.php?f=53)
-   -   Inserting logout link into Montezuma (http://forum.bytesforall.com/showthread.php?t=23461)

flyboy Apr 16, 2016 10:57 PM

Inserting logout link into Montezuma
 
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?

CrouchingBruin Apr 17, 2016 01:20 AM

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.
Code:

<?php
// 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.

flyboy Apr 17, 2016 02:20 AM

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?

juggledad Apr 17, 2016 06:38 PM

Try this, add the following to the end of function.php
HTML Code:

//Logout Shortcode
function logout_func ($atts, $content = null) {
        extract(shortcode_atts(array(
                '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"]'); ?>

flyboy Apr 19, 2016 12:15 PM

Thank you JD, you da man, as always.
Side note, sent you a PM regarding something unrelated a few days ago =)


All times are GMT -6. The time now is 01:18 AM.

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