How to add buttons to share in social networks VK and OK?
AI-generated summary
In a support thread titled ‘How to add buttons will be shared in VK and OK?’, 11145 asks how to add social sharing buttons for VK and OK to a Discourse site, including a screenshot of the desired layout. Stranik provides a working JavaScript code snippet using Discourse’s widget API to inject Facebook, OK, and VK share buttons into the topic map area, along with accompanying CSS for styling and positioning. The buttons open in new tabs and use URL-encoded links for sharing. Stranik notes that the code may not be perfect but functions, and encourages customization of the design. Finally, dax points to an official theme component for adding social share buttons, available at social-share-component, suggesting it as a more streamlined, maintained solution. The thread offers both a custom code approach and a recommended plugin-based alternative for adding VK and OK sharing functionality.
You can also try
<script type="text/discourse-plugin" version="0.4">
api.decorateWidget('topic-map:before', dec => {
const link = window.location.href;
const urlfb = "http://www.facebook.com/sharer.php?u=" + encodeURIComponent(link);
const urlok = "http://www.ok.ru/dk?st.cmd=addShare&st.s=1&st._surl=" + encodeURIComponent(link);
const urlvk = "https://vk.com/share.php?url=" + encodeURIComponent(link);
return dec.rawHtml(`
<div class="test"><a class="fb" href="${urlfb}" target="_blank"><i class="fa fa-facebook fa-lg" aria-hidden="true"></i></a>
<a class="ok" href="${urlok}" target="_blank"><i class="fa fa-odnoklassniki fa-lg" aria-hidden="true"></i></a>
<a class="vk" href="${urlvk}" target="_blank"><i class="fa fa-vk fa-lg" aria-hidden="true"></i></a>
</div>`);
});
</script>
CSS -
.test {
display: inline-block;
margin-top: -50px;
position: absolute;
}
.test a.ok{
margin-left: 15px;
margin-right: 15px;
}
.test a{color: #999;}
.test a:hover{color: #666;}
I tried it, do not know right or wrong. Div are, you can change the design as you wish…
The theme component to add an extra social button is now ready

