V9 logout via a custom link

I need to add a link (hard coded) that logs out the current user.

I’ve use this in the past, but doesn’t seem to work for v9:

echo '<li class="log-out"><a href="'. URL::to('/login', 'logout', \Core::make('helper/validation/token')->generate('logout')) .'">Log out</a></li>';

Have you tried

<?php echo Core::make('helper/navigation')->getLogInOutLink() ?>

It uses this function

public function getLogInOutLink()
{
if (!id(new User())->isLoggedIn()) {
$url = URL::to(‘/login’);
$label = t(‘Log in’);
} else {
$url = URL::to(‘/login’, ‘do_logout’, id(new Token())->generate(‘do_logout’));
$label = t(‘Log out’);
}
return sprintf(‘%s’, $url, $label);
}

Thanks, I’ll give that a go

newbie to ConcreteCMS here…I too would like to utilize this bit of code, where/which file would I add this to? TIA…Floyd

Welcome! So you just place it where ever you want the link to appear.

So it could be in your header or a custom template for the autonav block etc.

Thank you for the super fast response, wasn’t expecting that! :slightly_smiling_face: That certainly helps, I’ll see if I can find that in the theme I’m using.
Again, thank you, I appreciate the help…Floyd

Try this free block: Login Return - Concrete CMS