skip to Main Content

I want to change this button names to something else, but just changing the page name doesn’t work.

Buttons i want to change names of

2

Answers


  1. Find the Id or class of that element and use jQuery to change the name.

    If the element is a Anchor tag, use the below code.

    jQuery(document).ready(function($) 
    {
    $("#button_id").text("New Text");
    });
    

    If the element is button, use below code based on type of button.

    <input type='button' value='Add' id='button_id'>
    jQuery(document).ready(function($) 
        {
    $("#button_id").attr('value', 'New Text'); 
    }):
    
    <input type='button' value='Add' id='button_id'>
    jQuery(document).ready(function($) 
        {
    $("#button_id").prop('value', 'New Text'); 
    });
    <!-- Different button types-->
    
    <button id='button_id' type='button'>Add</button>
    jQuery(document).ready(function($) 
        {
    $("#button_id").html('New Text');
    });
    
    Login or Signup to reply.
  2. From the screenshot, it seems like you are trying to change the text of a menu link (My Account). If so make sure that you haven’t given any custom name for My Account page in the WordPress navigation.

    Inspect the page using developer tools and find the Class/Id of that element.
    Then you can use jQuery to alter the content using the below code.

    Using ID Selector:

    jQuery(document).ready(function($) 
    {
    $("#myaccountbuttonId").text("New Button Text");
    });
    

    Using Class Selector

    jQuery(document).ready(function($) 
    {
    $(".myaccountbuttonClass").text("New Button Text");
    });
    

    If you want to change the text of Add to Cart button, use the below code.

    // To change add to cart text on single product page
    add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' ); 
    
    function woocommerce_custom_single_add_to_cart_text() {
        return __( 'Buy Now', 'woocommerce' ); 
    }
    
    // To change add to cart text on product archives(Collection) page
    add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );  
    
    function woocommerce_custom_product_add_to_cart_text() {
        return __( 'Buy Now', 'woocommerce' );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search