In my custom post type there is a custom taxonomy that has the usual Title, Slug and Description fields.
I'm expecting the end user to not understand what the slug is for, and in my case it needs to be a language code e.g. en_GB, so I just want to be able to rename the Slug label to read "Language Code" instead.
TLDR; Can I rename the slug label of a custom taxonomy?
In my custom post type there is a custom taxonomy that has the usual Title, Slug and Description fields.
I'm expecting the end user to not understand what the slug is for, and in my case it needs to be a language code e.g. en_GB, so I just want to be able to rename the Slug label to read "Language Code" instead.
TLDR; Can I rename the slug label of a custom taxonomy?
Share Improve this question asked Jul 25, 2019 at 8:09 WongKongPhooeyWongKongPhooey 1134 bronze badges 2 |1 Answer
Reset to default 2As SallyCJ mentioned, gettext
is really the only option you have with this, because the Slug labels are hardcoded in the Core of WordPress.
https://core.trac.wordpress/browser/tags/5.2/src/wp-admin/edit-tags.php#L439
Here is a snippet I wrote and tested that should work for you, and it will only run on the backend and only on the two pages where you will see the and want to change the Slug:
add_action('current_screen', 'current_screen_callback');
function current_screen_callback($screen) {
// Put some checks and balances in place to only replace where and when we need to
if(
is_object($screen) &&
($screen->base==='edit-tags' || $screen->base==='term') &&
$screen->taxonomy==='custom_tax_slug'){
add_filter( 'gettext', 'change_out_slug_labels', 99, 3 );
}
}
function change_out_slug_labels($translated_text, $untranslated_text, $domain){
if(stripos( $untranslated_text, 'slug' )!== FALSE ){
$translated_text = str_ireplace('Slug', 'Language Code', $untranslated_text);
}
return $translated_text;
}
current_screen
is an admin only hook, so the call to swap out what you need is only called in the backend. I took the change_out_slug_labels()
function out so that you can use it on the front end if you need to.
I hope this helps!!!
gettext
filter. – Sally CJ Commented Jul 25, 2019 at 11:00