PHP code example of pixelshelsinki / social-share

1. Go to this page and download the library: Download pixelshelsinki/social-share library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pixelshelsinki / social-share example snippets



use Pixels\Components\SocialShare\Share;

// Current url
$facebook_share = Share::facebook();
$twitter_share  = Share::twitter();
$linkedin_share = Share::linkedin();
$whatsapp_share  = Share:: whatsapp();

// Given url.
$facebook_share = Share::facebook('https://www.pixels.fi/');
$twitter_share  = Share::twitter('https://www.pixels.fi/');
$linkedin_share = Share::linkedin('https://www.pixels.fi/');
$whatsapp_share = Share::whatsapp('https://www.pixels.fi/');



use \Timber\Twig_Function;

add_filter( 'get_twig', array( 'add_share_functions' ) );

function add_share_functions( $twig ) {
    // Social share functions.
    $twig->addFunction( new Twig_Function( 'facebook_share', '\\Pixels\\Components\\SocialShare\\Share::facebook' ) );
    $twig->addFunction( new Twig_Function( 'twitter_share', '\\Pixels\\Components\\SocialShare\\Share::twitter' ) );
    $twig->addFunction( new Twig_Function( 'linkedin_share', '\\Pixels\\Components\\SocialShare\\Share::linkedin' ) );
    $twig->addFunction( new Twig_Function( 'whatsapp_share', '\\Pixels\\Components\\SocialShare\\Share::whatsapp' ) );

    return $twig;
}