login_site_html_link
云策文档标注
概述
login_site_html_link 是一个 WordPress 过滤器钩子,用于修改登录页面页脚显示的“前往站点”链接。开发者可以通过此钩子自定义链接的 HTML 输出。
关键要点
- 过滤器钩子:login_site_html_link,用于过滤登录页面的“Go to site”链接。
- 参数:接受一个字符串参数 $link,表示当前站点首页 URL 的 HTML 链接。
- 来源:在 login_footer() 函数中调用,位于 wp-login.php 文件中。
- 版本:从 WordPress 5.7.0 版本开始引入。
- 用途:允许开发者修改链接的文本、URL 或样式,以适应特定需求。
代码示例
add_filter( 'login_site_html_link', 'wpdocs_login_site_html_link_cb' );
/**
* Filters the “Go to site” link displayed in the login page footer.
*
* @return string $html_link Modified "Go to Site" link.
*/
function wpdocs_login_site_html_link_cb() {
$html_link = sprintf(
'%s',
esc_url( home_url( '/' ) ),
sprintf(
/* translators: %s: Site title. */
_x( '← Go to %s', 'site' ),
get_bloginfo( 'title', 'display' )
)
);
return $html_link;
}注意事项
- 代码示例应添加到子主题的 functions.php 文件末尾,以避免主题更新时被覆盖。
- 使用 esc_url() 和 get_bloginfo() 等函数确保输出安全且符合 WordPress 标准。
- 此钩子仅影响登录页面页脚的链接,不影响其他部分的登录界面。
原文内容
Filters the “Go to site” link displayed in the login page footer.
Parameters
$linkstring-
HTML link to the home URL of the current site.
Source
echo apply_filters( 'login_site_html_link', $html_link );
Changelog
| Version | Description |
|---|---|
| 5.7.0 | Introduced. |
Skip to note 2 content
Muhammad Arslan
Modify the “Go to site” link displayed in the login page footer.
Copy and paste the following the child theme’s function.php file at the very end.
add_filter( 'login_site_html_link', 'wpdocs_login_site_html_link_cb' ); /** * Filters the “Go to site” link displayed in the login page footer. * * @return string $html_link Modified "Go to Site" link. */ function wpdocs_login_site_html_link_cb() { $html_link = sprintf( '<a href="%s" rel="nofollow ugc">%s</a>', esc_url( home_url( '/' ) ), sprintf( /* translators: %s: Site title. */ _x( '← Go to %s', 'site' ), get_bloginfo( 'title', 'display' ) ) ); return $html_link; }