Add Social Share Buttons in WordPress Without a Plugin

Every time someone shares your post on social media, you get free traffic, free visibility, and a small vote of confidence that search engines notice. But most visitors will not share your content if sharing feels like work. They are not going to copy your URL, open another app, and paste it. You need to put a share button right under their nose.
The usual advice is to install a share button plugin. That works, but many of those plugins load heavy third-party scripts, add tracking code, and slow your pages down. There is a better way: you can add social share buttons with plain links, a little PHP, and a bit of CSS. No plugin, no bloat, no scripts from outside your site.
This guide shows you three no-plugin methods, from the easiest link-based approach to a fully automatic PHP solution, plus styling tips to make your buttons look professional.
Why do share buttons matter for your blog?
Share buttons do three jobs for you at once. First, they remove friction: one click and the visitor is on the share screen with your post already loaded. Second, they act as social proof, because a row of share icons signals that your content is worth passing along. Third, every share brings referral traffic and backlinks that strengthen your site over time.
The best part is that these buttons cost you nothing in performance when you build them without a plugin. Plain share links are just HTML. They add zero JavaScript and zero external requests, so your pages stay as fast as they were before.
Share buttons vs follow buttons: what is the difference?
Before we build anything, let us clear up a common mix-up. Share buttons help visitors share the current page with their own followers. Follow buttons ask visitors to follow your accounts. They serve opposite directions: share buttons push your content outward, follow buttons pull people toward your profiles.
This guide covers share buttons. If you want visitors to message you directly instead, a WhatsApp chat button is a better tool for that job, and a click to call button works well for service businesses.
Method 1: Add share links with a Custom HTML block (easiest)
Every major social network offers a share URL: a simple link that opens its share dialog with your page pre-filled. You can drop these links into a Custom HTML block or a Buttons block anywhere in your post, and they work instantly with no code knowledge required.
The share URL formats
Replace the placeholders with your post URL and title. Here are the formats for the main networks:
Facebook:
https://www.facebook.com/sharer/sharer.php?u=YOUR-POST-URL
X (Twitter):
https://twitter.com/intent/tweet?text=YOUR-POST-TITLE&url=YOUR-POST-URL
LinkedIn:
https://www.linkedin.com/sharing/share-offsite/?url=YOUR-POST-URL
WhatsApp:
https://wa.me/?text=YOUR-POST-TITLE%20YOUR-POST-URL
Pinterest:
https://pinterest.com/pin/create/button/?url=YOUR-POST-URL&description=YOUR-POST-TITLE
Email:
mailto:?subject=YOUR-POST-TITLE&body=YOUR-POST-URL
Important: URL-encode your titles
Share URLs break if your title contains spaces or special characters like question marks and ampersands. Always URL-encode the title and URL before pasting them in. That means replacing spaces with %20, question marks with %3F, and ampersands with %26. You can use any free online URL encoder to do this in seconds. If you skip this step, some share links will open with a truncated or broken message.
How to add them in the editor
Open the post, add a Custom HTML block where you want the buttons, and paste your share links as anchor tags. Give each link target="_blank" so the share dialog opens in a new tab and visitors do not lose your page. Alternatively, use the Buttons block and paste each share URL into a button, which gives you nicer looking buttons with zero HTML.
Method 2: Auto-append share buttons with a small PHP snippet
Adding links manually to every post gets old fast. This snippet hooks into the_content (documented in the WordPress developer reference) and automatically appends a row of share links to the end of every single post. Set it up once, and every post on your site gets share buttons forever.
Where to put the code
As always, never edit your parent theme. Use a child theme’s functions.php or the free Code Snippets plugin from the official WordPress plugin directory. Create a new snippet, set it to run on the front end, and paste the code below.
add_filter( 'the_content', 'vtg_auto_share_buttons' );
function vtg_auto_share_buttons( $content ) {
if ( ! is_single() || ! is_main_query() ) {
return $content;
}
$url = urlencode( get_permalink() );
$title = urlencode( get_the_title() );
$buttons = '<div class="vtg-share-buttons">';
$buttons .= '<span>Share this post:</span> ';
$buttons .= '<a href="https://www.facebook.com/sharer/sharer.php?u=' . $url . '" target="_blank" rel="noopener">Facebook</a> ';
$buttons .= '<a href="https://twitter.com/intent/tweet?text=' . $title . '&url=' . $url . '" target="_blank" rel="noopener">X</a> ';
$buttons .= '<a href="https://www.linkedin.com/sharing/share-offsite/?url=' . $url . '" target="_blank" rel="noopener">LinkedIn</a> ';
$buttons .= '<a href="https://wa.me/?text=' . $title . '%20' . $url . '" target="_blank" rel="noopener">WhatsApp</a> ';
$buttons .= '<a href="mailto:?subject=' . $title . '&body=' . $url . '">Email</a>';
$buttons .= '</div>';
return $content . $buttons;
}
The snippet grabs the current post URL and title, URL-encodes them automatically (so you never have to do the encoding by hand), and builds share links for Facebook, X, LinkedIn, WhatsApp, and email. The is_single() check makes sure the buttons only appear on individual post pages, not on your homepage or archive listings.
Notice the rel="noopener" attribute on the links. That is a small security best practice for any link that opens in a new tab, and it costs you nothing to include.
Method 3: Style the buttons with custom CSS
Plain text links work, but styled buttons get clicked far more often. Add this CSS in Customizer, then Additional CSS, to turn the snippet’s links into proper branded buttons.
.vtg-share-buttons {
margin-top: 30px;
padding: 18px;
border-top: 1px solid #e2e2e2;
}
.vtg-share-buttons span {
display: block;
font-weight: bold;
margin-bottom: 12px;
}
.vtg-share-buttons a {
display: inline-block;
margin: 0 8px 8px 0;
padding: 8px 16px;
border-radius: 999px;
color: #ffffff;
text-decoration: none;
font-size: 14px;
}
.vtg-share-buttons a:hover {
opacity: 0.85;
color: #ffffff;
}
To give each network its brand color, add attribute selectors that target the link destinations. This is a clean trick that needs no extra classes:
.vtg-share-buttons a[href*="facebook.com"] { background: #1877f2; }
.vtg-share-buttons a[href*="twitter.com"] { background: #000000; }
.vtg-share-buttons a[href*="linkedin.com"] { background: #0a66c2; }
.vtg-share-buttons a[href*="wa.me"] { background: #25d366; }
.vtg-share-buttons a[href*="mailto"] { background: #777777; }
Rounded pill buttons with brand colors look familiar and trustworthy, because visitors recognize the colors from the networks themselves. If you want square or circular buttons instead, change the border-radius value. Our guide to adding custom CSS in WordPress covers more ways to safely add and preview CSS changes.
Where should you place the share buttons?
Placement matters more than most people think. Buttons below the content consistently outperform buttons at the top, because that is where the reader is right after finishing your post, exactly when they are most likely to share it.
On desktop, a floating vertical sidebar that follows the scroll can work well for long articles, since the buttons stay visible the whole time. On mobile, skip the floating sidebar entirely: it eats screen space and annoys readers. The below-content position from Method 2 is the safest choice that works everywhere.
Why is the no-plugin approach better for performance?
The methods in this guide add zero external scripts. The links are plain HTML, the styling is a few lines of your own CSS, and the PHP runs only when the page is generated. You get the same sharing functionality with none of the performance cost.
Frequently Asked Questions
Do share buttons work without JavaScript?
Yes, and that is the whole point of this approach. Share URL links are ordinary links, so they work with JavaScript disabled, on every browser, and on every device. Plugin-based buttons often break or show nothing when scripts fail to load.
Can I add share buttons to pages, not just posts?
Yes. In the PHP snippet, the is_single() check limits the buttons to posts. Change it to is_singular() and the buttons will also appear on pages. You can combine both conditions if you want posts and pages covered at once.
Will these share buttons show share counts?
No. Share counts require API calls to each network, which is exactly the kind of third-party bloat this guide avoids. In practice, most networks have removed or restricted their public count APIs anyway, so counts are unreliable even with plugins. Clean buttons without counts perform just fine.
Why do my share links show a broken title on some networks?
That almost always means the title was not URL-encoded. Special characters like ampersands and question marks cut the share text off at the wrong place. If you used Method 1, re-encode the title with an online URL encoder. Method 2 handles encoding automatically, so switching to the snippet fixes it permanently.
Last updated: October 2026.



