Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Share links shortcode

Type [share_links] to add plain share links for X, Facebook, LinkedIn, WhatsApp and email. No scripts, no tracking, no cookies.

  • Type PHP
  • Runs Where you put the [share_links] shortcode
  • Category Shortcodes
  • Tested with WordPress 7.1
PHP
<?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.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.