block editor - Change the text of the publish button to Save

admin2025-01-08  6

I am trying to change the text of the publish button to save

function change_publish_button( $translation, $text ) {

    if ( $text == 'Publish' )
        return 'Save';

    return $translation;
}

add_filter( 'gettext', 'change_publish_button', 10, 2 );

I am trying to run the above code but it doesn't change the text of the publish button, can anyone please tell what is wrong with this code or suggest any new method. Thanks in advance

Update I want to change the publish button shown in the figure below.

I am trying to change the text of the publish button to save

function change_publish_button( $translation, $text ) {

    if ( $text == 'Publish' )
        return 'Save';

    return $translation;
}

add_filter( 'gettext', 'change_publish_button', 10, 2 );

I am trying to run the above code but it doesn't change the text of the publish button, can anyone please tell what is wrong with this code or suggest any new method. Thanks in advance

Update I want to change the publish button shown in the figure below.

Share Improve this question edited Feb 6, 2019 at 6:51 phatskat 3,1741 gold badge18 silver badges26 bronze badges asked Feb 6, 2019 at 4:14 Mohit NihalaniMohit Nihalani 415 bronze badges 4
  • The original text has a "..." after it, so $text isn't Publish. – Jacob Peattie Commented Feb 6, 2019 at 6:48
  • @JacobPeattie Even after changing it to "..." it doesn't work. – Mohit Nihalani Commented Feb 6, 2019 at 7:18
  • 1 It's probably a single ellipsis character. Just inspect it in the browser and copy the exact text. – Jacob Peattie Commented Feb 6, 2019 at 8:22
  • note that the filter is for PHP based translations, Gutenberg has JS based translations, this will require a JS based solution – Tom J Nowell Commented Nov 3, 2022 at 17:46
Add a comment  | 

2 Answers 2

Reset to default 0

Put below code into your theme functions.php and try

function change_publish_button( $translation, $text ) {

    if ( $text == 'Publish...' )     // Your button text
        $text = 'Save';

    return $text;
}

add_filter( 'gettext', 'change_publish_button', 10, 2 );

This one is worked for me

Hope it will help you!

Try this:

function translate_publish( $translated_text, $untranslated_text, $domain ) {
    if( stripos( $untranslated_text, 'Publish' ) !== FALSE ) {
        $translated_text = str_ireplace( 'Publish', 'Save', $untranslated_text ) ;
    }
    return $translated_text;
}
if(is_admin()){
    add_filter( 'gettext', 'translate_publish', 99, 3 );
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736269479a1355.html

最新回复(0)