• Resolved PODxt

    (@podxt)


    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/ 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)
  • 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

    (@podxt)

    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.