简体   繁体   English

如何将Wordpress注销重定向到自定义URL

[英]How to redirect a Wordpress logout to custom URL

I have scoured the web for the last 45 minutes and still not found a simple description of how to send a user, logging out of WordPress, to a custom URL. 我在过去的45分钟内浏览了网页,但仍然没有找到如何将用户退出WordPress发送到自定义网址的简单说明。

I've come across this ; 我遇到过这个 ;

add_filter( 'logout_url', 'my_logout_url' );
    function my_logout_url( $url ) {
       return 'http://yourdomain.com/?a=logout';
    }

..but it does not describe where to paste that code. ..但它没有描述粘贴该代码的位置。 And i am not using a 'members' plugin. 我没有使用'成员'插件。

Surely there is just something that can be added to the Theme functions.php file or a edit to general-template.php to specify a URL? 当然有一些东西可以添加到Theme functions.php文件或编辑到general-template.php来指定URL? I'm not even wanting a different site domain. 我甚至不想要一个不同的网站域名。 Just back to the login page would be fine, but I would rather be able to specify an entire custom 'link' somewhere in the code. 回到登录页面会很好,但我宁愿能够在代码中的某处指定一个完整的自定义“链接”。 www.example.com www.example.com

How/where can I do this? 我如何/在哪里这样做?

Many thanks in advance for yor help or advice 非常感谢您的帮助或建议

Basic 基本

I know only 2 hooks when logout happen. 当注销发生时我只知道2个钩子。 This is logout_url and wp_logout . 这是logout_urlwp_logout Usually, I use the wp_logout in the next way 通常,我会以下一种方式使用wp_logout

function your_prefix_redirect() {
    wp_redirect('https://google.com/');
    die;
}
add_action('wp_logout', 'your_prefix_redirect', PHP_INT_MAX);

Notice, I specified priority as maximum INT, because some other code may do anything else major while logout happen 注意,我将优先级指定为最大INT,因为在注销发生时,其他一些代码可能会执行其他任何操作

Where to place the code? 在哪里放置代码?

You should to try the next ways: 你应该尝试下一个方法:

  1. Place the code inside the function.php into your active theme function.php的代码放入活动主题中
  2. Create a basic plugin has the code above 创建一个基本插件有上面的代码

I don't know about function.php , but inside the plugin the code above working well. 我不知道function.php ,但在插件里面上面的代码运行良好。

How to create a Wordpress basic plugin 如何创建Wordpress基本插件

  1. Move to folder wp-content/plugins 移至文件夹wp-content/plugins
  2. Create a file your-some-prefix-logout-custom-url.php 创建一个文件your-some-prefix-logout-custom-url.php
  3. Open new file and put in next: 打开新文件并输入下一个:

     <?php /* Plugin Name: Custom logout URL Author: Your_Name */ function your_prefix_redirect() { wp_redirect('https://google.com/'); die; } add_action('wp_logout', 'your_prefix_redirect', PHP_INT_MAX); 

Activate the new plugin in Wordpress admin panel after you done all actions above. 完成上述所有操作后,在Wordpress管理面板中激活新插件。 If your plugin isn't show in the plugin list then create any folder in wp-content/plugins and move your plugin into new folder. 如果你的插件没有显示在插件列表中,那么在wp-content/plugins创建任何文件夹并将你的插件移动到新文件夹中。 The comment before the code block is requirement. 代码块之前的注释是必需的。 Read the plugin handbook if you are interested in this 如果您对此感兴趣,请阅读插件手册

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM