Estimated reading time: 4 min
If you want a manual function in WordPress that allows you to share posts on your Facebook Page with a button, you can achieve this using a custom function in your themeβs functions.php
file. Here’s how:
Title: Add a “Share on Facebook” Button in WordPress Posts
Why Add a Facebook Share Button?
Adding a “Share on Facebook” button to your WordPress posts allows visitors to easily share your content with their audience, increasing engagement and traffic to your website.
Method 1: Using a Plugin (Easy Way)
If you want a quick solution without coding, you can use a plugin like AddToAny Share Buttons or Shared Counts.
Steps to Install a Plugin:
- Log in to your WordPress dashboard.
- Go to Plugins > Add New.
- Search for AddToAny Share Buttons or Shared Counts.
- Click Install Now and then Activate.
- Go to Settings > AddToAny and configure the button display.
- Save changes, and the share button will appear on your posts.
Method 2: Adding a Custom Facebook Share Button (Manual Code)
If you prefer a manual approach, you can add a custom Facebook Share button using a simple code snippet.
Steps to Add the Code:
- Open your WordPress functions.php file (or use a custom plugin for better management).
- Add the following function:
function custom_facebook_share_button($content) {
if (is_single()) {
$post_url = get_permalink();
$post_title = get_the_title();
$fb_share_url = "https://www.facebook.com/sharer/sharer.php?u=" . urlencode($post_url);
$button_html = '<div style="margin-top:20px;">
<a href="' . esc_url($fb_share_url) . '" target="_blank" style="background:#1877F2; color:#fff; padding:10px 15px; text-decoration:none; border-radius:5px; font-weight:bold;">
π’ Share on Facebook
</a>
</div>';
$content .= $button_html;
}
return $content;
}
add_filter('the_content', 'custom_facebook_share_button');
What This Code Does:
- It checks if the post is a single post (not homepage or archive).
- It generates a Facebook Share URL for the post.
- It appends a styled button at the end of the post.
Method 3: Using a Shortcode (More Flexibility)
If you want to place the button anywhere in your post, you can use a shortcode.
Add this code to functions.php
:
function facebook_share_shortcode() {
$post_url = get_permalink();
$fb_share_url = "https://www.facebook.com/sharer/sharer.php?u=" . urlencode($post_url);
return '<a href="' . esc_url($fb_share_url) . '" target="_blank" style="background:#1877F2; color:#fff; padding:10px 15px; text-decoration:none; border-radius:5px; font-weight:bold;">π’ Share on Facebook</a>';
}
add_shortcode('facebook_share', 'facebook_share_shortcode');
How to Use the Shortcode:
Simply insert [facebook_share]
anywhere in your post where you want the button to appear.
Method 4: Adding a Manual Share Button in Admin Dashboard
If you want a button inside the WordPress admin panel to manually share a post, you can add this to the post edit screen.
Steps:
- Add the following function to
functions.php
:
function add_facebook_share_meta_box() {
add_meta_box('facebook_share', 'Manual Facebook Share', 'facebook_share_meta_box_callback', 'post', 'side', 'high');
}
add_action('add_meta_boxes', 'add_facebook_share_meta_box');
function facebook_share_meta_box_callback($post) {
$post_url = get_permalink($post->ID);
$fb_share_url = "https://www.facebook.com/sharer/sharer.php?u=" . urlencode($post_url);
echo '<a href="' . esc_url($fb_share_url) . '" target="_blank" class="button button-primary">π’ Share on Facebook</a>';
}
What This Does:
- Adds a “Manual Facebook Share” button inside the WordPress post editor.
- Clicking it opens Facebookβs share window for the current post.
- You can customize the caption before posting.

Final Thoughts
This is a manual function that allows you to share posts on Facebook with a simple button:
- Frontend Button: Adds a button below each post for visitors.
- Admin Dashboard Button: Lets admins share posts directly from WordPress.
Conclusion
Adding a Facebook Share button to WordPress posts helps increase visibility and engagement. Whether you use a plugin, custom code, or shortcode, you now have multiple options to make sharing easy for your audience.
Would you like additional features, such as tracking shares or adding other social platforms? π
Let me know if you need any modifications or enhancements! π
Discover more from HelpZone
Subscribe to get the latest posts sent to your email.