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.
Opens WPIDE on
Code
// 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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.