Top

You CAN Change the Term Display for ‘Tags’ and ‘Categories’ in WordPress

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:

 

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

 

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):

 

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

 

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:’

 

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

 

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

 

if ( ! function_exists( 'translate_stuff' ) ) {
 /**
 * Replace the term 'tags' with another term
 *
 * @link https://ayrne.com/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');
 }

 

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.

Post a Comment

Previous Next
Close
Test Caption
Test Description goes like this