• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Draft / Remove target _blank from the Scriptless Social Sharing Email button

Remove target _blank from the Scriptless Social Sharing Email button

Last updated on August 27, 2018 by Sal Ferrarello

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).

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Draft, Programming, Solution Tagged With: WordPress Filter, WordPress Plugin

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in