There are buttons social networks with their own design. I want to make it so that when you click on each button a person can share a post with other users on your page. For contact and facebook, I found where <?php echo get_permalink(); ?> <?php echo get_permalink(); ?> current wordpress page

 <div> <p>Какой-то текст</p> <p>Поделиться</p> <div class="social_icons_holder"> <ul class="social_icons clearfix"> <li class="facebook"> <span class="tool-tip">Facebook</span> <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo get_permalink(); ?>" target="_blank" title="Поделиться в Facebook"><i class="fa fa-facebook"></i></a> </li> <li class="instagram"> <span class="tool-tip">Instagram</span> <a target="_blank" href="http://instagram.com"><i class="fa fa-instagram"></i></a> </li> <li class="vk"> <span class="tool-tip">Vkontakte</span> <a href="https://vk.com/share.php?url=<?php echo get_permalink(); ?>" target="_blank" title="Поделиться ВКонтакте"><i class="fa fa-vk"></i></a> </li> <li class="foursquare"> <span class="tool-tip">Foursquare</span> <a target="_blank" href="https://ru.foursquare.com/"><i class="demo-icon icon-foursquare-1"></i></a> </li> </ul> <!--/ .social-icons--> </div> </div> 

  • one
    Each of the social networks has its own mechanism for this. For example, facebook has it written here: developers.facebook.com/docs/plugins/share-button . There is no single mechanism. - Vartlok
  • @Vartlok is good, let's use Facebook as an example - how can I add a button so that the page I’m on is added to share with the user. for each page and post to create your own button? - Vasya

1 answer 1

On the example of Facebook: Working example here .

  1. You need to register your application to get the app id and app secret.
  2. On the site you need to connect Facebook SDK. This is done after registering your application.
  3. After that, insert the button on your website. To make the div dynamic, leave the data-href = "" parameter empty. You can also write a function that returns the address of the page where you are. But then you have to print the div using javascript. For example:

  getCurrentUrl(); function share() { window.location.href = 'https://www.facebook.com/sharer/sharer.php?u=' + window.location.href; } function getCurrentUrl() { return window.location.href; } 
 div { padding: 10px; height: 10px; width: 30px; background-color: blue; border-radius: 5px; } 
 <button onclick='share()'>Button</button> <div data-href="" data-layout="button"></div>