Share links shortcode
Type [share_links] to add plain share links for X, Facebook, LinkedIn, WhatsApp and email. No scripts, no tracking, no cookies.
<?php
// [share_links]
$url = rawurlencode( (string) get_permalink() );
$title = rawurlencode( wp_strip_all_tags( (string) get_the_title() ) );
$links = 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}",
);
$out = '<ul class="share-links">';
foreach ( $links as $name => $href ) {
$out .= '<li><a href="' . esc_url( $href, array( 'https', 'mailto' ) ) . '" target="_blank" rel="noopener nofollow">' . esc_html( $name ) . '</a></li>';
}
return $out . '</ul>';
How to use it
Type [share_links] in a post, a page or a Shortcode block.
In these packs
- Shortcodes: Handy shortcodes for dates, breadcrumbs, buttons, share links, members-only content and more.