dqajyxqem115006813 2017-08-02 22:35
浏览 160
已采纳

如何将Wordpress注销重定向到自定义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.

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

  • 写回答

1条回答 默认 最新

  • douzhou7124 2017-08-03 00:52
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了