# Simple Share Buttons After Posts

> Adds lightweight share links for X, Facebook, LinkedIn, WhatsApp and email at the end of each post, with no third-party scripts or tracking.

- Type: PHP
- Runs: Frontend only
- Category: [Frontend & Design](https://wpide.com/library/category/frontend/)
- Tags: social, sharing, content, privacy
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/frontend-share-buttons/

## Code

```php
add_filter( 'the_content', function ( $content ) {
    if ( ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
        return $content;
    }

    $url   = rawurlencode( get_permalink() );
    $title = rawurlencode( wp_strip_all_tags( get_the_title() ) );

    // Network => share URL.
    $networks = array(
        'X'        => "https://x.com/intent/post?url={$url}&text={$title}",
        'Facebook' => "https://www.facebook.com/sharer/sharer.php?u={$url}",
        'LinkedIn' => "https://www.linkedin.com/sharing/share-offsite/?url={$url}",
        'WhatsApp' => "https://wa.me/?text={$title}%20{$url}",
        'Email'    => "mailto:?subject={$title}&body={$url}",
    );

    $links = '';

    foreach ( $networks as $name => $share ) {
        $links .= sprintf(
            '<a href="%1$s" %2$s style="display:inline-block;margin:0 8px 8px 0;padding:6px 14px;border:1px solid currentColor;border-radius:20px;font-size:14px;text-decoration:none;">%3$s</a>',
            esc_url( $share ),
            'Email' === $name ? '' : 'target="_blank" rel="noopener nofollow"',
            esc_html( $name )
        );
    }

    return $content . '<div class="wpide-share" style="margin-top:2em;"><p style="margin-bottom:.5em;font-weight:600;">Share this post</p>' . $links . '</div>';
}, 30 );
```

## Notes

Edit $networks to remove networks you do not need. Uses plain links, so nothing loads until a visitor clicks.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Simple Share Buttons After Posts" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
