Title: Replacing String in Shortcode
Last modified: December 21, 2021

---

# Replacing String in Shortcode

 *  Resolved [domrohrer](https://wordpress.org/support/users/domrohrer/)
 * (@domrohrer)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/replacing-string-in-shortcode/)
 * I have a few issues with a plugin I’m working with (businessdirectoryplugin.com)
   with it’s translation.
 * I’m having a multilanguage site and the plugin has some issues with certain links
   with the translation.
 * For example, on the button “Annuaire” (see link to the page) it always redirects
   to /de/suche/, that’s correct for the german version, but for french it should
   be /fr/cherche and for italian /it/cerca.
 * I came up with the idea, that I could replace the concerned strings on the specific
   translated pages where this issue is present and added this code to myfunctions.
   php for the french post:
 *     ```
       add_filter('the_content', 'filter_post_479');
       function filter_post_479($content){
       	if ( is_singular() && in_the_loop() && is_main_query() ) { 
             global $post;
             if ($post->ID == 479){ // 479 is post/page ID you have found
                $string = "de/suche"; //your string to be replaced
                $replace = "fr/cherche";
                $content = str_replace( $string, $replace, $content );
          }
          }
          return $content;
       }
       ```
   
 * Unfortunately, that didn’t work.
    I think because the plugin is loaded into the
   site via shortcode, and so the filter the_content doesn’t apply there.
 * The contents post is as following:
 *     ```
       <h1>Annuaire</h1>
       [businessdirectory]
       ```
   
 * Can someone help me out, how I can replace these strings inside of the shortcode
   or if there is a better way to do this task?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Freplacing-string-in-shortcode%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/replacing-string-in-shortcode/#post-15185693)
 * shortcodes are run at priority 11 on the same filter
 *     ```
       // Shortcodes.
       add_filter( 'the_content', 'do_shortcode', 11 ); // AFTER wpautop().
       ```
   
 * So you need to run your filer at 12 or higher
 * e.g.
 * `add_filter('the_content', 'filter_post_479', 12, 1);`
 *  Thread Starter [domrohrer](https://wordpress.org/support/users/domrohrer/)
 * (@domrohrer)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/replacing-string-in-shortcode/#post-15187562)
 * Thanks a lot! Worked as expected. 🙂
 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/replacing-string-in-shortcode/#post-15188933)
 * Thanks for letting me know.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Replacing String in Shortcode’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 2 participants
 * Last reply from: [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * Last activity: [4 years, 5 months ago](https://wordpress.org/support/topic/replacing-string-in-shortcode/#post-15188933)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
