About the Login/Register button linking

Dear ATHEMES

How can i change the Login/Register button linking?
The Login/Register button is linking the wp-login.php page.
I wanna change it to link the my-account page.

Thank you.

Hello there,

To accomplish it, try doing the below steps:

  1. Add the below function to your child theme’s functions. Or you can use a functionality plugin like Code Snippets if you don’t want to use a child theme
    /**
     * Get WC page URL
     */
    add_action( 'wp_enqueue_scripts', 'leto_child_wc_pages', 9999 );
    function leto_child_wc_pages() {

      $wc_pages = array(
        'my_account' => get_permalink( wc_get_page_id( 'myaccount' ) ),
      );

      wp_localize_script( 'leto-main', 'wc_pages', $wc_pages );

    }
  1. Install and activate the TC Custom JavaScript plugin
  2. Go To Appearance > Custom JavaScript
  3. Paste the following code into the provided box
    (function($){

      if( $('.nav-link-account a').length ) {
        $('.nav-link-account a').attr('href', wc_pages.my_account);
      }

    })(jQuery);
  1. Update

Regards,
Kharis

I used Code Snippets and the following steps, it works fine now.
Thanks for your help.

And Can help me again for


please?

Hi,

This seems to only work when in home page. How do we change it for all the pages?

Thank you.

Regards
Manhua

Hello there,

Are you other pages cached? Try flushing it if applied and re-run your test.

If it doesn’t change anything, please share your complete code. Maybe there’s something we could correct.

Regards,
Kharis

1 Like

Hi kharisblank,

I have tried and it didn’t work for me. This is my code.

Child theme’s function.php

<?php function my_theme_enqueue_styles() { $parent_style = 'leto-style'; wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme()->get('Version') ); } add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); /** * Get WC page URL */ add_action( 'wp_enqueue_scripts', 'leto_child_wc_pages', 9999 ); function leto_child_wc_pages() { $wc_pages = array( 'my_account' => get_permalink( wc_get_page_id( 'myaccount' ) ), ); wp_localize_script( 'leto-main', 'wc_pages', $wc_pages ); } /** * Enable Log Out link */ add_action( 'wp_enqueue_scripts', 'leto_child_logout_link', 9999 ); function leto_child_logout_link() { $wc_pages = array( 'logout' => wp_logout_url(get_permalink( wc_get_page_id( 'myaccount' ) )), ); wp_localize_script( 'leto-main', 'wc_pages', $wc_pages ); } ?>

TC Custom Javascript

(function($){

  if( $('.nav-link-account a').length ) {
    $('.nav-link-account a').attr('href', wc_pages.my_account);
  }

})(jQuery);

(function($){

if( $(‘body’).hasClass(‘logged-in’) && $(’.nav-link-account’).length ) {
var logoutLink = wc_pages.logout;
$(’.nav-link-account > a’).attr(‘href’, logoutLink).text(‘Log Out’);
}

})(jQuery);

If not, is there a way to remove the right nav bar so i can add my own?

Thank you!

Hi manhua,

I had the same problem including a few others.
you need to download a other plugin with the same functions.
this plugin is broke, u can try the best you can but it wont work.
I needed a week to figure this out. If you want a name of a other plugin Custom CSS & JS.
a plugin in plugin download page.

Kind Regards,

Kevin

@kharisblank

Hi Kharis,

Does the plugin actually work on the test panel ?
A few say it wont work until they download a other plugin.

Kind Regards,

Kevin

Hello there,

You could use the Functionality plugin to add this functions to your site.

    /**
     * Get WC page URL
     */
    add_action( 'wp_enqueue_scripts', 'leto_child_wc_pages', 9999 );
    function leto_child_wc_pages() {

      $wc_pages = array(
        'my_account' => get_permalink( wc_get_page_id( 'myaccount' ) ),
      );

      wp_localize_script( 'leto-main', 'wc_pages', $wc_pages );

    }

For this jQuery code

    (function($){

      if( $('.nav-link-account a').length ) {
        $('.nav-link-account a').attr('href', wc_pages.my_account);
      }

    })(jQuery);

use TC Custom Javascript.

Regards,
Kharis

Hi Kharisblank,

The code works fine by itself but I can’t get it to work together with below code, would you be able to advise how?

Thank you very much.

Regards
Manhua

@liemerseenergieservi

I have also been trying to figure out the theme for a week haha. The plugin seems fine with me though.
Did you try to get the button to change to “Log out” or “Logged in” after user signed in?
I believe most people would want to do that…please advise if you managed to…

Regards
Manhua

I have solved the issue.
Thank you!

1 Like