Ben Sullivan

Founder at Ayrne
Artist, Traveler, and Lover of the Beauty of Life

Some people may not like the default terms that are printed for things like categories and tags in WordPress. I know this for a fact because I happen to be one of these people. While it’s easy enough to create rules for permalink conventions, there isn’t any intuitive way to change how these terms appear on posts and pages – or in the WordPress administrative options. So I did what any sane person would do and wrote a function for it in PHP.

 

To get started, we’ll need the following:

  • FTP or FSTP access to the web-root directory of the WordPress instance we want to modify or SSH access.
  • For FTP/FSTP access, you’ll need a client like Filezilla to connect to your host.
  • For SSH, you’l need an application like Putty.
  • You’ll want to create a backup of your existing functions.php file before editing it
  • You may want to create a backup of your site before editing code as well – or, if you’re feeling brave, you could go all Rambo.

Note: if you’re using SSH to edit the file, you’d run the following command to open it for editing:

 

[codesyntax lang=”php”]

sudo nano /path/to/your/themes/functions.php #replace the eaxmple path with the actual path to the functions.php file for your theme.

[/codesyntax]

 

Otherwise, you’ll locate the file in your FTP client and open it with your favorite editor.

 

To change how the term ‘tag’ displays we’ll copy this code at the bottom of the code contained in the funtions.php file, just after the final closing ‘}.’  This will be for whatever theme is active in WordPress (in my case, my active theme is located at /html/wp-content/themes/ayrne/functions.php):

 

[codesyntax lang=”php”]

if ( ! function_exists( 'translate_tag' ) ) {
 /**
 * Replace the term 'tags' with another term
 *
 * @link https://ayrne.io/change-replace-term-display-tags-categories-wordpress/
 */
 function translate_tag($translated) { 
 $translated = str_ireplace('Tag', 'Topic', $translated);
 return $translated; 
 }
 add_filter('gettext', 'translate_tag' );
 }

[/codesyntax]

 

As you can see, we’ve set the term ‘tag’ to be replaced with the term ‘topic.’ The action part of this is defined by (‘Tag’, ‘Topic‘, $translated). You  can replace the term ‘topic‘ with whatever you’d like. It’s worth noting that this code will also switch plural instances of ‘tag’ (i.e. ‘tags’) with ‘topics,’ so don’t create a redundant entry for that.

 

Here’s another example where we’re swapping out the term ‘category‘ with ‘notacategory:’

 

[codesyntax lang=”php”]

if ( ! function_exists( 'translate_category' ) ) {
 /**
 * Replace the term 'tags' with another term
 *
 * @link https://ayrne.io/change-replace-term-display-tags-categories-wordpress/
 */
 function translate_category($translated) { 
 $translated = str_ireplace('category', 'notacategory', $translated);
 return $translated; 
 }
 add_filter('gettext', 'translate_category' );
 }

[/codesyntax]

 

And here’s what it looks like when we translate multiple terms:

 

[codesyntax lang=”php”]

if ( ! function_exists( 'translate_stuff' ) ) {
 /**
 * Replace the term 'tags' with another term
 *
 * @link https://ayrne.io/change-replace-term-display-tags-categories-wordpress/
 */
 function translate_stuff($translated) {
 $translated = str_ireplace('Tag', 'Topic', $translated);
 $translated = str_ireplace('Category', 'Fluffernutter', $translated);
 $translated = str_ireplace('Chart', 'Blarb', $translated);
 return $translated;
 }
 add_filter('gettext', 'translate_stuff');
 }

[/codesyntax]

 

Pretty easy, right? And this same code snippet can be used to translate virtually any term that is printed by WordPress via a function. I plan to make it even easier and when I have the time, I’ll write a plugin for this and share it here and via the WordPress plugins repository.

Tags:

About the Author
Founder , Ayrne
I am an artist, traveler, and lover of the beauty of life
  • Show Comments (0)

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of

Support our site

If you find this site helpful, please consider using our affiliate links. Ayrne may earn a small commission from your purchase, but it won’t cost you anything at all and in some cases, it may even save you money! We use affiliate links instead of banner ads to provide you with a cleaner, more focused experience on our website.