How to Add Social Media Sharing Buttons to WordPress Without a Plugin

Social sharing buttons let visitors post your content to Facebook, Twitter, LinkedIn, and other networks. Adding them without a plugin keeps your site lean — no third-party tracking scripts unless you choose them.

Problem: Adding social sharing buttons via a plugin loads JavaScript from third-party social networks on every page, increasing page weight and introducing GDPR-relevant third-party tracking without visitor consent.

Solution: Build static sharing links using each network's URL scheme — https://twitter.com/intent/tweet?url=..., https://www.facebook.com/sharer.php?u=... — generated in PHP with get_permalink() and rawurlencode(get_the_title()). No external scripts are loaded.

Option 1 — Plain link approach (no extra scripts, privacy-friendly)

Each major social network provides a share URL endpoint you can link to directly. No JavaScript required:

function get_share_links( $post_id = null ) {
    $post_id  = $post_id ?: get_the_ID();
    $url      = urlencode( get_permalink( $post_id ) );
    $title    = urlencode( get_the_title( $post_id ) );

    return [
        'facebook'  => 'https://www.facebook.com/sharer/sharer.php?u=' . $url,
        'twitter'   => 'https://twitter.com/intent/tweet?url=' . $url . '&text=' . $title,
        'linkedin'  => 'https://www.linkedin.com/sharing/share-offsite/?url=' . $url,
        'whatsapp'  => 'https://wa.me/?text=' . $title . '%20' . $url,
    ];
}

// In a template:
$links = get_share_links();
foreach ( $links as $network => $href ) {
    printf(
        '<a href="%s" target="_blank" rel="noopener noreferrer" class="share-btn share-btn--%s">%s</a>',
        esc_url( $href ),
        esc_attr( $network ),
        esc_html( ucfirst( $network ) )
    );
}

Option 2 — ShareThis custom buttons (one script, full style control)

Register at sharethis.com, get a publisher key, then enqueue their SDK and add data-network attributes to your buttons:

add_action( 'wp_enqueue_scripts', function() {
    if ( is_single() ) {
        wp_enqueue_script(
            'sharethis',
            '//platform-api.sharethis.com/js/sharethis.js#product=custom-share-buttons',
            [],
            null,
            true
        );
    }
} );

<div class="st-custom-button"
     data-network="facebook"
     data-url="<?php the_permalink(); ?>"
     data-title="<?php the_title(); ?>">Facebook</div>

<div class="st-custom-button"
     data-network="twitter"
     data-url="<?php the_permalink(); ?>"
     data-title="<?php the_title(); ?>">Twitter</div>

NOTE: Option 1 (plain links) is faster, privacy-friendlier, and works without JavaScript. The share counts won't be displayed inline, but share counts have become less important as a social proof signal. Option 2 is the right choice if you need click analytics or custom share counts.