This topic has 10 replies, 3 voices, and was last updated 7 years, 11 months ago ago by Olga Barlow
I would like to change My Acoount text for username when is logged in. How Can I do this?
I use this code snipped to show username, but not in My account link.
: function my_custom_menu_item($items)
{
if(is_user_logged_in())
{
$user=wp_get_current_user();
$name=$user->display_name; // or user_login , user_firstname, user_lastname
$items .= '<li><a href="">Welcome '.$name.'</a></li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_custom_menu_item');
Hello,
“My account” link text can be changed from the ‘xstore/framework/theme-functions.php’ file. Function name containing this text is etheme_get_links
Regards
Can I put php condition to show username???
Yes, you can put the username there as well. Just need to customize the PHP function etheme_get_links
Do you have an example to do this? I don´t have enought expertise to do this 🙁
Try to replace this function with the following code
function etheme_get_links($args) {
extract(shortcode_atts(array(
'short' => false,
'popups' => true,
), $args));
$links = array();
$reg_id = etheme_tpl2id('et-registration.php');
$login_link = wp_login_url( get_permalink() );
if( class_exists('WooCommerce')) {
$login_link = get_permalink( get_option('woocommerce_myaccount_page_id') );
}
if(etheme_get_option('promo_popup')) {
$links['popup'] = array(
'class' => 'popup_link',
'link_class' => 'etheme-popup',
'href' => '#etheme-popup',
'title' => etheme_get_option('promo-link-text'),
);
if(!etheme_get_option('promo_link')) {
$links['popup']['class'] .= ' hidden';
}
if(etheme_get_option('promo_auto_open')) {
$links['popup']['link_class'] .= ' open-click';
}
}
if( etheme_get_option('top_links') ) {
if ( is_user_logged_in() ) {
$user=wp_get_current_user();
$name=$user->display_name; // or user_login , user_firstname, user_lastname
if( class_exists('WooCommerce')) {
if ( has_nav_menu( 'my-account' ) ) {
$submenu = wp_nav_menu(array(
'theme_location' => 'my-account',
'before' => '',
'container_class' => 'menu-main-container',
'after' => '',
'link_before' => '',
'link_after' => '',
'depth' => 100,
'fallback_cb' => false,
'walker' => new ETheme_Navigation,
'echo' => false
));
} else {
$submenu = '<ul>';
$permalink = wc_get_page_permalink( 'myaccount' );
foreach ( wc_get_account_menu_items() as $endpoint => $label ) {
$url = ( $endpoint != 'dashboard' ) ? wc_get_endpoint_url( $endpoint, '', $permalink ) : $permalink ;
$submenu .= '<li class="' . wc_get_account_menu_item_classes( $endpoint ) . '"><a href="' . esc_url( $url ) . '">' . esc_html( $label ) . '</a></li>';
}
$submenu .= '</ul>';
}
$links['my-account'] = array(
'class' => 'my-account-link',
'link_class' => '',
'href' => get_permalink( get_option('woocommerce_myaccount_page_id') ),
'title' => esc_html__( 'Welcome, ', 'xstore' ) . $name,
'submenu' => $submenu
);
}
// $links['logout'] = array(
// 'class' => 'logout-link',
// 'link_class' => '',
// 'href' => wp_logout_url(home_url()),
// 'title' => esc_html__( 'Logout', 'xstore' )
// );
} else {
$login_text = ($short) ? esc_html__( 'Sign In', 'xstore' ): esc_html__( 'Sign In or Create an account', 'xstore' );
$links['login'] = array(
'class' => 'login-link',
'link_class' => '',
'href' => $login_link,
'title' => $login_text
);
if(!empty($reg_id)) {
$links['register'] = array(
'class' => 'register-link',
'link_class' => '',
'href' => get_permalink($reg_id),
'title' => esc_html__( 'Register', 'xstore' )
);
}
}
}
return apply_filters('etheme_get_links', $links);
}
Regards
Wooooowwwww. awesome..THANKS A LOT!
You are welcome!
I would be very appreciated if you leave 5-stars rating for our theme on TF https://themeforest.net/downloads and good comment about support.
Thank you!
Regards
I made this change in xstore/framework/theme-functions.php to show username in header, If I update theme I losst all configs right? Can I put this theme-functions.php in child theme and works fine or I need to crete a folder called framework and put there the php file?
Hello,
You will lose all the changes if you made them in the parent theme. Do all the changes in child theme.
If you want to change any function copy-paste this function into functions.php of child theme and do the changes there, you don’t need to copy all the content of theme-functions.php, just necessary function. Then it will work.
More details how to use child theme you can find here https://codex.wordpress.org/Child_Themes
Regards
Tagged: header, my account, secure login, username, woocommerce, wordpress templates
You must be logged in to reply to this topic.Log in/Sign up