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:

with

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

Leave a Reply