WordPress退出后跳转到指定页面

之前发布的一篇教程:WordPress替换登陆后的默认首页,可实现登录WordPress后台后跳转到指定页面。现在问题又来了,能不能实现退出(登出)后台后跳转到指定页面呢?而不是这个:

WordPress退出后跳转到指定页面

这个问题也很好解决,将下面的php代码放到当前主题的functions.php中即可:
add_filter('logout_url', 'ludou_logout_redirect', 10, 2);

function ludou_logout_redirect($logouturl, $redir) {
$redir = 'http://www.ludou.org/'; // 这里改成你要跳转的网址
return $logouturl . '&redirect_to=' . urlencode($redir);
}

这样你在后台页面右上角点击退出后,就可以跳转到指定页面了。如果你是想在前台添加一个退出链接,点击后退出登录并跳转到指定站内页面,可以使用以下代码(代码中网址改成你的):
<?php if ( $user_ID ) { ?>
<a href="<?php echo wp_logout_url( 'http://www.ludou.org/' ); ?>" title="Logout">Logout</a>
<?php } ?>

如果是要跳转到首页,可以使用下面的代码:
<?php if ( $user_ID ) { ?>
<a href="<?php echo wp_logout_url( home_url() ); ?>" title="Logout">Logout</a>
<?php } ?>

如果是要跳转到退出前所在的页面,可以使用以下代码:
<?php if ( $user_ID ) { ?>
<a href="<?php echo wp_logout_url( home_url(add_query_arg(array(),$wp->request)) ); ?>" title="Logout">Logout</a>
<?php } ?>

yiguochun

yiguochun(http://blog.0660hf.com/)0660SEO博客是以seo网站优化,Seo学习,sEO知识,SEO网络推广技巧及站长分享经历的媒体博客,为SEO爱好者和广大站长提供一个SEO案例分享和交流的平台,从分享SEO分享交流过程中带来更多的心满意足。

You may also like...

3 Responses

  1. WWE Mayhem hack说道:

    I loved as much as you’ll receive carried out right here.

    The sketch is attractive, your authored subject
    matter stylish. nonetheless, you command get bought an edginess over that you wish be delivering the following.

    unwell unquestionably come more formerly again since exactly the same nearly very
    often inside case you shield this hike.

  2. When I originally commented I clicked the “Notify me when new comments are added” checkbox and now
    each time a comment is added I get three e-mails with the
    same comment. Is there any way you can remove
    people from that service? Thank you!

  3. Hello, i think that i noticed you visited my site thus i got here to return the desire?.I’m attempting to find issues to enhance my web site!I assume its
    adequate to make use of a few of your ideas!!

发表评论

电子邮件地址不会被公开。