How to include hashtags with Facebook’s share function

A little while back I ran into a problem when trying to allow users to share a page on Facebook. I wanted to include hashtags with Facebook’s share feature in the URL. The page loaded content via AJAX, and appended a fragment identifier (#) and a short string to the URL. When user’s tried to share this page, the hashtag and the rest of the string was being stripped. A quick Google search pointed me to a post on StackOverflow that revealed that I wasn’t the only one who couldn’t figure this out.

After pulling out my hair, the answer came to me. Encode the hashtag – replace # with %23 in the URL. For example, replace:

http://www.example.com/#/path/to/whatever/

with

http://www.example.com/%23/path/to/whatever/

This may seem simple – and it is – but hopefully it can save you from some unnecessary frustration.

2 thoughts on “How to include hashtags with Facebook’s share function”

Leave a Reply to Ryan Cancel reply

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