skip to Main Content

In the Woocommerce login module there is a piece of text that needs to be edited and a register link placed inside of the message. But if I just add in the HTML tags around the link then the code shows up in the text and not as a link.

This is the original code in the form-login.php file

'message'  => esc_html__( 'If you have shopped with us before, please enter your details below. If you are a new customer, please proceed to the Billing section.', 'woocommerce' ),

This is how I have changed it to include Register and the link:

'message'  => esc_html__( 'If you have shopped with us before, please enter your details below. If you are a new customer, please' . '<a href="#login" class="register-text">Register</a>' . ' to proceed.', 'woocommerce' ),

I also tried the following but it broke the site so not an option:

'message'  => esc_html__( 'If you have shopped with us before, please enter your details below. If you are a new customer, please' . '<a href="#login" class="register-text">Register</a>' . ' to proceed.', 'woocommerce' ),

I just need the word “Register” to become a link with a specific class for the color and hover (which is created in the CSS). How can I do this please?

2

Answers


  1. Chosen as BEST ANSWER

    Thanks to Nathan Arnold. It took me a few tries, but I finally got it right. The final code looks as such:

    'message'  => __( 'If you have shopped with us before, please enter your details below. If you are a new customer, please' . '<a href="#login" class="register-text"> Register</a>' . ' to proceed.', 'woocommerce' ),
    

    I don't understand why the '__' needed to be there, but if I remove it then nothing worked, so I left it in.


  2. esc_html escapes your HTML code, so
    <a href="#login" class="register-text">Register</a> becomes &lt;a href=&quot;#login&quot; class=&quot;register-text&quot;&gt;Register&lt;/a&gt;.

    You’ll need to remove the esc_html() function.

    (Be careful with this though, as serving unescaped HTML could be dangerous if using dynamic content Learn more…)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search