Twitter Share Link Format

When Twitter changed the user layout, it also changed the url that allows a website to share a particular page or post through a tweet.

Here is a new url format that works:

https://twitter.com/intent/tweet?hashtags=technical&original_referer=https://david-e-young.com/twitter-share-link-format/&ref_src=twsrc%5Etfw&related=twitterapi%2Ctwitter&text=Twitter%20Share%20Link%20Format&tw_p=tweetbutton&url=https://david-e-young.com/twitter-share-link-format/&via=dave3young

When that link is clicked, the Twitter API will open the windows below:
Twitter Share Box

If multiple hashtags are needed, they can be added with a space and #:
?hashtags=technical%20%23tips%20%23website

That will generate the hashtags #technical #tips #website

Since this is a WordPress site, the following PHP lines have been added to the single.php page to construct the Share button for this post:
$page_title = esc_html(get_the_title());
$page_link = esc_url(get_permalink());
echo '<a href="https://twitter.com/intent/tweet?hashtags=technical&original_referer=' . $page_link . '&ref_src=twsrc%5Etfw&related=twitterapi%2Ctwitter&text=' . $page_title . '&tw_p=tweetbutton&url=' . $page_link . '&via=dave3young"' . ' title="Tweet this!" alt="Click this button to share on Twitter" target="_blank">' . '<img src="/images/twitter.png" alt="Share on Twitter Button"></a>';

Share this post:
Share on Twitter Button   Share on Facebook Button   Share on LinkedIn Button   Share on Reddit Button

david

A developer with more than a decade of professional programming experience on multiple platforms. Windows (Win32 through .NET), as well as Web technologies.