Tweet Button - how to include query string with URL?


How do I get the Tweet button include the full URL of the current page, including the query string? E.g.

The default code from Twitter ( works on my site, except it only provides the first part, e.g.

I have quite a few pages* on one section of my site that are populated with varying content from a database, depending on the values in the query string, so it’s critical the share links have the query string or else the page is devoid of content.

After a couple hours of fruitless effort trying to get this to work I figured I ask for some help. If anybody needs me to provide additional info let me know.

*It’s really just one page with dynamic content, and thus only one Tweet button.


You should be URL encoding the passed URL. Example:

If you do not pass an explicit URL parameter the link canonical of the page may be used.


Thanks for the reply.

Unless I’m misunderstanding (very possible), the method you showed via jsfiddle is something that would have to be set manually, for every page, correct? If so, I don’t think that will work, because I have over 50 versions of a single page, where the version/content is determined by the query string (it pulls a bunch of info from a database).

Based on some additional research it looks like I’ll probably have to use some JavaScript in order for it to recognize the full URL.


If you vary the content of a page based on a query parameter then you will want to set the canonical link of the page to make sure references to the page are accurately captured and extra query parameters with no effect are collapsed.

Passing a URL parameter to the Tweet intent is the best way to explicitly define the URL you would like a viewer to share.