如何将Wordpress注销重定向到自定义URL [英] How to redirect a Wordpress logout to custom URL

查看:143
本文介绍了如何将Wordpress注销重定向到自定义URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在过去45分钟内一直在网上进行搜索,但仍然找不到有关如何将用户(从WordPress注销)发送到自定义URL的简单描述.

我遇到了;

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

..但未描述将代码粘贴到何处.而且我没有使用成员"插件.

当然可以将一些内容添加到Theme函数.php文件中,或进行编辑以指定URL的general-template.php吗?我什至不想要其他站点域.只需返回登录页面就可以了,但是我宁愿能够在代码中的某个地方指定整个自定义链接". www.example.com

如何/在何处执行此操作?

在此先感谢您的帮助或建议

解决方案

基本

注销时我只知道2个钩子.这是logout_urlwp_logout.通常,我会以另一种方式使用wp_logout

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

注意,我将优先级指定为最大INT,因为注销时某些其他代码可能会做其他重要的事情

代码在哪里放置?

您应该尝试以下方法:

  1. function.php内的代码放入活动主题
  2. 创建具有上面代码的基本插件

我不了解function.php,但是在插件内部,上面的代码运行良好.

如何创建Wordpress基本插件

  1. 移动到文件夹wp-content/plugins
  2. 创建文件your-some-prefix-logout-custom-url.php
  3. 打开新文件,然后放入下一个文件:

    <?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);
    

完成上述所有操作后,在Wordpress管理面板中激活新插件.如果您的插件未显示在插件列表中,请在wp-content/plugins中创建任何文件夹,然后将插件移至新文件夹. 代码块之前的注释是必需的.如果您对此插件感兴趣,请阅读插件手册. >

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.

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? 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

How/where can I do this?

Many thanks in advance for yor help or advice

解决方案

Basic

I know only 2 hooks when logout happen. This is logout_url and wp_logout. Usually, I use the wp_logout in the next way

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

Where to place the code?

You should to try the next ways:

  1. Place the code inside the function.php into your active theme
  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.

How to create a Wordpress basic plugin

  1. Move to folder wp-content/plugins
  2. Create a file 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. 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. The comment before the code block is requirement. Read the plugin handbook if you are interested in this

这篇关于如何将Wordpress注销重定向到自定义URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆