I like to use the Scriptless Social Sharing WordPress plugin to add Share buttons to my blog posts. Recently I had a client notice that because the Email Share button has target="_blank"
in the HTML markup, it opens a new tab when clicked. This is great behavior if you’re using web based email (e.g. Gmail), however if you’re using an email application on your computer, you end up with a blank tab.
Using the following code removes the target="_blank"
attribute from the email share button (and does not modify any of the other buttons).
/**
* Remove target="_blank" from the Scriptless Social Sharing email share button.
*/
add_filter( 'scriptlesssocialsharing_link_markup', function( $markup, $button ) {
if ( 'email' !== $button['name'] ) {
return $markup;
}
return str_replace( ' target="_blank"', '', $markup );
}, 10, 2 );
Update
This change has been made to the actual plugin (see GitHub Issue 12). Until the next version of the plugin is released, you can still use this code (and it won’t cause any problems once the update is released).
Leave a Reply