How can one add a toggle button to the post menu and implement an action for that toggle button in a Discourse plugin?

I’m new to Discourse plugin making and would appreciate some help with adding a toggle button to the post menu and implementing its action in the plugin.

Hi @omppatil perhaps this post might help you get in the right direction:

Also if you are new to Discourse plugin programming:



You can use addPostMenuButton

api.addPostMenuButton('coffee', () => {
 return {
   action: 'drinkCoffee',
   icon: 'coffee',
   className: 'hot-coffee',
   title: 'coffee.title',
   position: 'first'  // can be `first`, `last` or `second-last-hidden`

Then you can add your action this way:

api.attachWidgetAction("post", "drinkCoffee", function () {

EDIT: Got Lillian’d :smile:. It would also be a good idea to follow the guides Lilly posted!


Therefore, what file structure should be implemented, and where should the above code be placed?

Reading the above linked topics should answer your related dev questions. It’s possible you could achieve what you want with a theme component instead of plugin. Thus, I would also add these to your reading list:

also, from the first link I posted:


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.