Why does clicking a link rendered by WP PHP with target="_blank" open in new tab and current tab?
So I know this kind of question has been asked in here, but mine appears to be different from others.
The code below shows that if there is a URL populate it and open it in a new tab, however, for some strange reason the link opens in a new tab (YAY!!) AND opens in the current tab (BOO!!). Why is it opening in both the new tab and the current tab?
I just checked in an incognito window and it happens there also so it doesn’t appear to be a cookie issue either.
<div class="box span4">
<?php if( $url1 != '' && $img1 != '' ): ?>
<a href="<?php echo esc_url( $url1 ); ?>" target="_blank" class="box-link">
<center><img class="box-image" src="<?php echo esc_url( $img1 ); ?>"/></center>
</a>
<?php else: ?>
<?php if( $img1 != '' ): ?>
<a class="box-no-url">
<center><img class="box-image" src="<?php echo esc_url( $img1 ); ?>"/></center>
</a>
<?php endif; ?>
<?php endif; ?>
<p><?php echo wp_kses( $text1, array( 'br' => array(), 'em' => array(), 'strong' => array() ) ); ?></p>
</div>
To see this code in action please visit http://www.tayloredhomeinspection.com/ and scroll down to the image with the InterNACHI seal in the middle gray box and click on it (or the text below it).
2
Answers
Here is the weave job I did that seems to have it working.
It looks like I have to keep the
target="_blank"
in the .php file and this should work for any changes I make in the theme and I have the file saved in case of theme updates.