2

我在做一个小项目,并想让这个场景发挥作用。我想在用户登录我的帐户页面标题时写“我的帐户”,当用户退出时,页面标题写“登录注册”。为了更好地解释图像:

  1. 对于已登录的用户

在此处输入图像描述

  1. 对于未登录的用户

在此处输入图像描述

我有此代码适用,但似乎没有改变什么。

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
}

有什么帮助吗?

4

1 回答 1

1

您可以使用以下内容:

add_filter( 'the_title', 'display_product_image_in_order_item' );
function display_product_image_in_order_item( $title ) {
    if( is_account_page() && $title === __('My Account', 'woocommerce') && ! is_user_logged_in() ) {
        $title = __( 'Account Login / Register', 'woocommerce' );
    }
    return $title;
}

代码位于您的活动子主题(或活动主题)的 function.php 文件中。测试和工作。

于 2020-07-10T21:55:22.077 回答