我想在块编辑器中更改发布按钮的文本,遇到了这个问题。根据给出的答案,它并没有改变文本。随着Gutenberg的更新,我意识到这必须用JavaScript来完成。我发现这样的反应:Changing text within the Block Editor
我在插件代码中应用了它(您也可以将其插入到您的Themes functions.php文件中)。
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 );
针对您的特定请求,您可以仅针对帖子ID执行以下操作:
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 );