Title: Gettext Filter issue
Last modified: August 24, 2016

---

# Gettext Filter issue

 *  [Bloodofeve](https://wordpress.org/support/users/bloodofeve/)
 * (@bloodofeve)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/gettext-filter-issue/)
 * I have tried to use ‘Gettext-filter-Wordpress’ for a eCommerce site I am building,
   the issue is my client wants two text strings swapped around, I read through 
   the instructions and added the code Which is show below, but I received the following
   error:
 * > Fatal error: Cannot redeclare my_text_strings() (previously declared in /homepages/
   > 24/d520177130/htdocs/.pomegranate/wp-content/themes/canvas-child/functions.
   > php:70) in /homepages/24/d520177130/htdocs/.pomegranate/wp-content/themes/canvas-
   > child/functions.php on line 91
 * The code I used is as follows:-
 *     ```
       /**
       * Change text strings
       *
       * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
       */
       function my_text_strings( $translated_text, $text, $domain ) {
       switch ( $translated_text ) {
       case 'Related Products' :
       $translated_text = __( 'You may also like...', 'woocommerce' );
       break;
       }
       return $translated_text;
       }
       add_filter( 'gettext', 'my_text_strings', 20, 3 );
       /**
       * Change text strings
       *
       * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
       */
       function my_text_strings( $translated_text, $text, $domain ) {
       switch ( $translated_text ) {
       case 'You may also Like...' :
       $translated_text = __( 'Related Products', 'woocommerce' );
       break;
       }
       return $translated_text;
       }
       add_filter( 'gettext', 'my_text_strings', 20, 3 );
       ```
   
 * Am I missing something here, and did I need to install a plugin? I am not a programmer
   so this is a little beyound my normal work area.

Viewing 1 replies (of 1 total)

 *  [Chris](https://wordpress.org/support/users/zenation/)
 * (@zenation)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/gettext-filter-issue/#post-6064944)
 * As the error message says, in PHP you can only declare a function (name) once.
   And you’re doing it twice with the lines
 * `function my_text_strings(...`
 * You should be better off using something like this
 *     ```
       <?php
       /**
       * Change text strings
       *
       * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
       */
       function my_text_strings( $translated_text, $text, $domain ) {
   
         switch ( $translated_text ) {
   
           case 'Related Products' :
             $translated_text = __( 'You may also like...', 'woocommerce' );
             break;
   
           case 'You may also Like...' :
             $translated_text = __( 'Related Products', 'woocommerce' );
             break;
   
           // add more cases if you like
   
           }
   
         }
   
         return $translated_text;
   
       }
       add_filter( 'gettext', 'my_text_strings', 20, 3 );
       ?>
       ```
   
 * instead of the code block you’ve posted.
 * And instead of _my\_text\_strings_ you should come up with a more unique and 
   descriptive name.

Viewing 1 replies (of 1 total)

The topic ‘Gettext Filter issue’ is closed to new replies.

## Tags

 * [gettext](https://wordpress.org/support/topic-tag/gettext/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [Chris](https://wordpress.org/support/users/zenation/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/gettext-filter-issue/#post-6064944)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
