首页 > 解决方案 > Is it possible to customize the logout page or create a custom logout page in Wordpress?

问题描述

At the moment if the user navigates to the default logout page it looks like this:

Logout

This is not consistent with the theme of my website so I would like this content inside my own custom page. Can this be done?

I have a plugin installed My Theme Plugin which is designed to let me specify a logout page but I do not know how to construct it.

标签: wordpresslogout

解决方案


由于这可能对其他人有所帮助,因此我将添加我的评论作为答案。

您需要最初使用logout_url过滤器 - https://developer.wordpress.org/reference/hooks/logout_url/

logout这将允许您在用户单击链接时设置页面。接下来,您只需创建所需的页面(基本 WordPress 页面、特殊模板等)。

在该页面上,您将使用wp_logout_url()设置Are you sure you want to logout文本的链接。例如

<a href="<?php echo wp_logout_url( home_url() ); ?>">Logout</a> 

这将在用户注销后将用户重定向到主页。

编辑:添加到内容的简码:

function wpso58817718_add_logout_link( $atts ){
    return '<a href="' . wp_logout_url( home_url() ) . '">Logout</a>';
}
add_shortcode( 'logout_link', 'wpso58817718_add_logout_link' );

然后你可以做[logout_link]

wp_logout_url( home_url() )如果您不希望它转到主页,则必须更新结束 URL 。


推荐阅读