How to add a Hashtag Button to your website
- Create a new anchor element with a
twitter-hashtag-buttonclass to allow the X for Websites JavaScript to discover the element and enhance the link into a Hashtag button. Set ahrefattribute value ofhttps://x.com/intent/tweetto create a link to the X web intent composer.
- Add your hashtag of interest as a
button_hashtagquery parameter value and a component of the anchor element’s inner text.
- Asynchronously load the X for Websites JavaScript using our loading snippet. The JavaScript snippet will check for an existing version on the page, initialize a function queue to be executed once the widgets JavaScript has loaded, and load the widgets JavaScript asynchronously from X’s CDN.
Define secondary hashtags
Include additional hashtags in pre-populated Post text using the hashtags web intent query parameter. A hashtag defined in thebutton_hashtag parameter and displayed in the button will appear before hashtags defined in the hashtags parameter.
JavaScript factory function
X’s widget JavaScript library supports dynamic insertion of a hashtag button using thetwttr.widgets.createHashtagButton function. Pass a hashtag, target container element, and the same options supported by the Post button JavaScript factory function.