Is there a way to change the text of the publish button on a custom post type to say some different? For example, Save instead of Publish. And also remove the draft button?
Leave a Reply
You must be logged in to post a comment.
Is there a way to change the text of the publish button on a custom post type to say some different? For example, Save instead of Publish. And also remove the draft button?
You must be logged in to post a comment.
If you look into
/wp-admin/edit-form-advanced.php
, you will find the meta box:Note the
__('Publish')
รขยย the function__()
leads totranslate()
where you get the filter'gettext'
.There are two ways to handle your problem: 1. Address the string in a single specialized function (be sure to match the correct textdomain!) or 2. use a more generic approach.
@Rarst has just now posted version 1, so I’ll add version 2. ๐
You don’t need to use the code as a plugin. Including it in your theme’s functions.php will be enough.
Update
To remove the original Save button (not sure what the ‘draft’ button is), add the following code to your functions.php/a plugin:
Yes, it’s ugly.
The code for hakre’s suggestion to use translation filter would be something like this:
This is not a full answer but some directions: Any text displayed surpasses a translation filter and can therefore be changed in a callback function (hook). So if the hook is only registered on the page where you would like to change that, job done.
The draft button could be “removed” by hiding it via CSS. The CSS could be injected into the
<head>
-tag of the admin with another callback. I think the filter is calledadmin_head
for that. It’s somehow dirty as the button still is there, for example if a user switches CSS off.For consistency, I’m assuming you’d prefer to use “Save” instead of “Publish” throughout WordPress instead of just on the text of the button.
Based on the solution provided by @Rarst, I expanded the code so it translates many (all?) other instances of the word “Publish” to the appropriate variation of “Save”.
For removing the Draft button, the answer given by @toscho contains a good solution.
Another approach would be unregister the metabox, then re-register that same box with differing values, namingly the publish text..
See the discussion i had here regarding moving a meta box, you should be able to apply something similar to rename that Publish text.
You could just find the button via jQuery and swap the text node for something else. That would be a piece of cake to do.
Much cleaner & easier solution.