Title: Help with a simple php code
Last modified: August 21, 2016

---

# Help with a simple php code

 *  Resolved [PODxt](https://wordpress.org/support/users/podxt/)
 * (@podxt)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/help-with-a-simple-php-code/)
 * Hi, I have this function in my functions.php file:
 *     ```
       <?php
       $return = str_replace('target="_blank" href="http://localhost/test/', 'href="http://localhost/test/', $return);
       ?>
       ```
   
 * I would like to replace [http://localhost/test/](http://localhost/test/) with
   something like:
    `<?php echo esc_url( home_url( ) ); ?>`
 * but I can’t do that because I need to close the php tag first before opening 
   it again. Problem is I don’t know where.
 * Thanks in advance!

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

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/help-with-a-simple-php-code/#post-4726822)
 * It’s pretty easy to do that. You just need to add that function inline. As you’re
   using the value twice, I’d save it to a variable to make the code that tiny bit
   faster:
 *     ```
       <?php
       $url = esc_url( home_url( ) );
   
       $return = str_replace('target="_blank" href="'.$url, $url, $return);
       ```
   
 *  Thread Starter [PODxt](https://wordpress.org/support/users/podxt/)
 * (@podxt)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/help-with-a-simple-php-code/#post-4726882)
 * Working great, thanks!

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

The topic ‘Help with a simple php code’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [PODxt](https://wordpress.org/support/users/podxt/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/help-with-a-simple-php-code/#post-4726882)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
