As 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.org/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!!!