# Share Links Below Posts

> Adds plain share links for X, Facebook, LinkedIn, WhatsApp and email under each blog post. No third-party scripts or tracking pixels are loaded.

- Type: PHP
- Runs: Frontend only
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: social, sharing, posts
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/share-links-after-posts/

## Code

```php
// Networks to show, in order. Available: x, facebook, linkedin, whatsapp, email.
$wpide_share_networks = array( 'x', 'facebook', 'linkedin', 'whatsapp', 'email' );
// Heading above the links.
$wpide_share_label = 'Share this post';

add_filter( 'the_content', function ( $content ) use ( $wpide_share_networks, $wpide_share_label ) {
    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() ) );
    $all   = array(
        'x'        => array( 'X', 'https://x.com/intent/post?url=' . $url . '&text=' . $title ),
        'facebook' => array( 'Facebook', 'https://www.facebook.com/sharer/sharer.php?u=' . $url ),
        'linkedin' => array( 'LinkedIn', 'https://www.linkedin.com/sharing/share-offsite/?url=' . $url ),
        'whatsapp' => array( 'WhatsApp', 'https://wa.me/?text=' . $title . '%20' . $url ),
        'email'    => array( 'Email', 'mailto:?subject=' . $title . '&body=' . $url ),
    );

    $links = '';

    foreach ( $wpide_share_networks as $network ) {
        if ( ! isset( $all[ $network ] ) ) {
            continue;
        }

        $external = 'email' !== $network ? ' target="_blank" rel="noopener noreferrer"' : '';
        $links   .= '<a class="wpide-share-' . esc_attr( $network ) . '" href="' . esc_url( $all[ $network ][1], array( 'https', 'mailto' ) ) . '"' . $external . ' style="display:inline-block;margin:0 .5em .5em 0;padding:.35em .8em;border:1px solid currentColor;border-radius:4px;text-decoration:none;">' . esc_html( $all[ $network ][0] ) . '</a>';
    }

    return $content . '<div class="wpide-share-links" style="margin-top:2em;"><p><strong>' . esc_html( $wpide_share_label ) . '</strong></p>' . $links . '</div>';
}, 30 );
```

## Notes

Remove networks you do not want from the $wpide_share_networks list.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Share Links Below 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/
