How to change “Publish” button text for specific page

I am trying to make one specific page on my wordpress installation to have a different text on the “Upload” button.

So i tried:

function change_settingspage_publish_button( $translation, $text ) {

    if ( '567' == get_the_ID() && $text == 'Publish' ) {

        return 'Save Settings';

    } else {

        return $translation;
    }
}
add_filter( 'gettext', 'change_settingspage_publish_button', 10, 2 );

(Where ‘567’ is the page id). but it doesn’t work. any ideas?

3 Answers
3

I wanted to change the Publish button’s text in the Block Editor and came across this question. With the answers given it wasn’t changing the text. With the Gutenberg update, I realized it would have to be done with JavaScript. I found this response: Changing text within the Block Editor

Which I applied in my plugin code (you can insert this into your Themes functions.php file, too).

function change_publish_button_text() {
// Make sure the `wp-i18n` has been "done".
  if ( wp_script_is( 'wp-i18n' ) ) :
  ?>
    <script>
      wp.i18n.setLocaleData({'Publish': ['Custom Publish Text']});
    </script>

    <script>
      wp.i18n.setLocaleData({'Publish…': ['Custom Publish Text']});
    </script>
  <?php
  endif;
}

add_action( 'admin_print_footer_scripts', 'change_publish_button_text', 11 );

Which to your specific request to target only on a post ID you can do this:

function change_publish_button_text() {
  global $post;
  if (get_the_ID() == '123') {
    // Make sure the `wp-i18n` has been "done".
    if ( wp_script_is( 'wp-i18n' ) ) :
      ?>
        <script>
          wp.i18n.setLocaleData({'Publish': ['Custom Publish Text']});
        </script>

        <script>
          wp.i18n.setLocaleData({'Publish…': ['Custom Publish Text']});
        </script>
      <?php
      endif;
    }
  }

add_action( 'admin_print_footer_scripts', 'change_publish_button_text', 11 );

Leave a Comment