# I want to move the Facebook and Twitter share buttons to post menu

**URL:** https://meta.discourse.org/t/i-want-to-move-the-facebook-and-twitter-share-buttons-to-post-menu/43472
**Category:** Development
**Created:** [April 29, 2016, 9:38pm UTC](https://meta.discourse.org/t/i-want-to-move-the-facebook-and-twitter-share-buttons-to-post-menu/43472 "2016-04-29T21:38:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)
#### Post date: [April 29, 2016, 9:38pm UTC](https://meta.discourse.org/t/i-want-to-move-the-facebook-and-twitter-share-buttons-to-post-menu/43472/1 "2016-04-29T21:38:06Z")

</div>

Continuing the discussion from [How can I custom share button?](https://meta.discourse.org/t/how-can-i-custom-share-button/20529/10):

I have added new post menu items for sharing to Facebook and Twitter.

![](https://global.discourse-cdn.com/meta/original/3X/4/a/4a94d163c719ffe47f4ede46975526299d2af118.png)

They do not have any functionality yet though. I was looking to hopefully piggy back on action of the original share actions for facebook and twitter but I am struggling with doing so.

I was also looking at the api documentation for adding a new share source, but it has not helped.

[https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/sharing.js.es6#L7](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/sharing.js.es6#L7)

What do I need to do to copy the `share` action of the current facebook and twitter buttons and place them on the post menu items I have created.

---

<div class="post-metadata">

### Author: ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)
#### Post date: [May 2, 2016, 4:39pm UTC](https://meta.discourse.org/t/i-want-to-move-the-facebook-and-twitter-share-buttons-to-post-menu/43472/2 "2016-05-02T16:39:51Z")

</div>

For anyone interested in the super hacky way I _completed_ this:

- I added two post menu buttons as per the screen shot in my original post (one for twitter and one for facebook).

- using `api.attachWidgetAction` I wired the button up to link to the appropriate share url, opening in a popup

So here I set the link and url. The link is the current topic a user is on (I will need to add some JS to include the specific post number a user tries to share).  
**UPDATE:** No hacky JS needed to get the post number. When you make the post menu button add `data` as a property like so:

```
api.addPostMenuButton('twitter-share', (attrs) => {
        return {
          action: 'twitter-share',
          icon: 'twitter',
          className: 'twitter-share',
          title: I18n.t('share.twitter'),
          data: {
            'share-url': attrs.shareUrl,
            'post-number': attrs.post_number
          },
          position: 'first' // can be `first`, `second`, `last` or `second-last-hidden`
        };
      });

```

This will result in the follow html for the button tag:

`data-share-url="/t/privacy-policy/6?u=stevenpslade" data-post-number="1"`

The url is the twitter or facebook share url, which is taken from `discourse/app/assets/javascripts/discourse/initializers/sharing-sources.js.es6`.  
I also set the `title` by getting the `.json` of the current topic:

```
var title;
      $.getJSON(window.location.href + '.json', function (data) { 
        var json = data;
        title = json.title;
      });

```

The urls open in a pop up, and the size of the pop up is dependant on if it is Facebook or Twitter (again taken from `sharing-sources.js.es6`).

The reason I share this hacky method is in the hopes that someone has a _way, way_ better idea. Ideally, I would want to just extend the current sharing logic and place it on the new post menu buttons 🤔
