Guides‎ > ‎

Create logout link

To create your own proper WordPress logout (or sign out) link, you need PHP.


Default usage
<a href="<?php echo wp_logout_url(); ?>" title="Logout">Logout</a> 

Logout and Redirect to Current Page
<a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a> 

Logout and Redirect to Homepage
<a href="<?php echo wp_logout_url( get_bloginfo('url') ); ?>" title="Logout">Logout</a>


Plain HTML

If you are in an iframe, you can use this hack to read the href

<a id="my_signout" href="/wp-login.php?action=logout" target="_top">Sign out</a>

<script type="text/javascript">if (-1 <"([^"]+)" title="Log out/)) document.getElementById('my_signout').href=RegExp.$1.replace(/&amp;/g, '&');</script>

"Sign out" link in menu

To add "Sign out" into the menu, add to footer.php

  // replace with your "Sign out" menu id
  var ae, e = document.getElementById('menu-item-722');

  if (e)
    ae = e.getElementsByTagName('a');

    if (ae)
      e = ae[0];

      if (e)
         e.href = '<?php echo wp_logout_url(); ?>'.replace(/&amp;/g, '&');