How to Make Links Open in a New Tab in the WordPress Author Bio

>How to Make Links Open in a New Tab in the WordPress Author Bio
  • browser new tab

If you accept guest posts on your WordPress blog, and you want to add an “About the Author” bio box for those posts, where the authors can add a few words about themselves and a link to their website, or Twitter, or whatever, then you probably want those links to open in a new tab.

Why? Well, if the links open in the same tab, it means they’ll load “over” your website, therefore disappearing from the user’s sight / attention.

If the links in the “About the Author” bio box will open in a new tab, then your website will remain in a separate tab for the users to come back to, and not forget about it.

The longer a user stays on your site, the better!

WordPress removes target=”_blank”

Since the “Biographical Info” box doesn’t have a text editor, you have to manually add the link, using HTML.

In order to open a link in a new tab, you have to add the target="_blank" attribute in the <a> tag (e.g. <a href=”https://example.com” target=”_blank”>Example.com</a>)

But as soon as you’ll press the Update User button, WordPress will remove the target="_blank" attribute, and the link will open in the same tab!

 

How to make the links in the “About the Author” bio open in a new tab

No, we won’t use a plugin, we’re going to get our hands dirty a bit. Just a bit.

No need to add one more plugin to the bloat for something that’s quite easy.

I strongly recommend having a child theme, otherwise the change will be removed with every theme update! Also, back up the file or the entire website before making any changes!

So, you’ll have to access your WordPress theme’s files.

There, you need to edit the functions.php file in your child theme (usually found in /public_html/wp-content/themes/YOURTHEMENAME-Child/functions.php), and add this code at the bottom:

add_filter( 'get_the_author_description', 'link_target_blank_author_desc' );
function link_target_blank_author_desc( $desc ) {
return str_replace( '<a', '<a target="_blank" ', $desc );
}

Save the file and that’s it!

You don’t have to add the target=”_blank” attribute anymore, in the bio box, because the code will open all the links in a new tab by default.

That’s a wrap

Hope you found the post useful and comprehensive.

Don’t forget to share it with your friends!

If you have questions, thoughts, or need help, please drop a comment, contact us, or message us Facebook.

You can also follow us on Twitter and subscribe to our YouTube channel.

If you want to start your own WordPress blog, or need a website for your business, our WordPress installation service is at your disposal!

Web Hosting
By | 2018-06-19T08:57:17+00:00 March 6th, 2018|Coding, Tips|0 Comments

Leave A Comment

Subscribe
SUBSCRIBE NOW

     Join the Weekly      Newsletter

Get WordPress guides and tutorials right in your inbox, once a week!
close-link