• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Draft / How to Add a Twitter Hashtag with Scriptless Social Sharing

How to Add a Twitter Hashtag with Scriptless Social Sharing

Last updated on April 24, 2019 by Sal Ferrarello

When using Scriptless Social Sharing, you may want to add a site wide hashtag to all of your tweets.

e.g. I might want to add #learnIronCode to all of the tweets created with the Twitter share button.

Before Adding Hashtag

Never use git push force 
salferrarello.com/never-git-push-force/
via @salcode

After Adding Hashtag

Never use git push force #learnIronCode
salferrarello.com/never-git-push-force/
via @salcode

Code to Add

Note The author of Scriptless Social Sharing, Robin Cornett, was kind enough to point out there is an even better way to do this than I had originally posted. I’ve updated this post to use her code.

add_filter( 'scriptlesssocialsharing_twitter_url', function ( $url ) {
    $hashtag = '#myHashTag';
    return str_replace(
        '&url=',
        '%20' . rawurlencode( $hashtag ) . '&url=',
        $url
    );
});
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, marketing, 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