钩子文档

logout_url

💡 云策文档标注

概述

logout_url 是一个 WordPress 过滤器,用于修改 wp_logout_url() 函数返回的注销 URL。它允许开发者自定义注销链接的路径和重定向参数。

关键要点

  • 过滤器名称:logout_url
  • 参数:$logout_url(HTML 编码的注销 URL)和 $redirect(注销后的重定向路径)
  • 应用于 wp_logout_url() 函数返回的 URL
  • 自 WordPress 2.8.0 版本引入

代码示例

add_filter( 'logout_url', 'my_logout_page', 10, 2 );
function my_logout_page( $logout_url, $redirect ) {
    return home_url( '/my-logout-page/?redirect_to=' . $redirect );
}

注意事项

  • 建议使用更高的优先级(如 20)而非默认的 10,以确保过滤器正确应用

📄 原文内容

Filters the logout URL.

Parameters

$logout_urlstring
The HTML-encoded logout URL.
$redirectstring
Path to redirect to on logout.

More Information

This filter is applied to the url returned by the function wp_logout_url() .

Source

return apply_filters( 'logout_url', $logout_url, $redirect );

Changelog

Version Description
2.8.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Example migrated from Codex:

    The following example changes the logout URL to a URL path relative to the home URL while keeping the same redirect URL.

    add_filter( 'logout_url', 'my_logout_page', 10, 2 );
    function my_logout_page( $logout_url, $redirect ) {
        return home_url( '/my-logout-page/?redirect_to=' . $redirect );
    }