Change the text of the publish button to Save

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.

Topic block-editor buttons publish Wordpress

Category Web


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

enter image description here

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 );
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.