我在做一个小项目,并想让这个场景发挥作用。我想在用户登录我的帐户页面标题时写“我的帐户”,当用户退出时,页面标题写“登录注册”。为了更好地解释图像:
- 对于已登录的用户
- 对于未登录的用户
我有此代码适用,但似乎没有改变什么。
function dynamic_label_change( $items, $args ) {
if ( ! is_user_logged_in() ) {
$items = str_replace( "My Account", "Account Login / Register ", $items );
}
return $items;
}
或者可能
// When user is on my account page and not logged in
if (is_account_page() && !is_user_logged_in()) {
echo '<h1 class="entry-title">'.__("My custom title",
"the_theme_slug").'</h1>'; // My custom title
} else {
the_title( '<h1 class="entry-title">', '</h1>' ); // the normal template
title
}
有什么帮助吗?

