Adding social media sharing buttons to your Jekyll blog posts can significantly increase your content's visibility and engagement. By allowing readers to easily share your posts on platforms like Facebook, Twitter, and LinkedIn, you can reach a broader audience and drive more traffic to your site.
Why Add Sharing Buttons?
Sharing buttons make it simple for visitors to distribute your content across their social networks. This not only enhances your blog's reach but also encourages more interaction and feedback from your audience. Additionally, social sharing can improve your SEO by increasing backlinks and traffic.
Methods to Add Sharing Buttons
There are several ways to incorporate social media sharing buttons into your Jekyll blog:
- Using third-party services like AddThis or ShareThis
- Adding custom HTML and JavaScript code
- Using Jekyll plugins or includes
Implementing Sharing Buttons with AddThis
One of the easiest methods is to use a service like AddThis. Here's how to add it to your Jekyll site:
Step 1: Sign Up for AddThis
Visit AddThis and create a free account. Once registered, customize your sharing tools and copy the provided code snippet.
Step 2: Insert the Code into Your Jekyll Layout
Open your Jekyll site's layout file (e.g., _layouts/post.html) and paste the AddThis script just before the closing </body> tag. For example:
<!-- AddThis Sharing Buttons -->
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=YOUR-PROFILE-ID"></script>
Replace YOUR-PROFILE-ID with your actual AddThis profile ID.
Custom Sharing Buttons with HTML and JavaScript
If you prefer more control, you can create your own sharing buttons using HTML and JavaScript. Here's a simple example for Facebook and Twitter:
<div class="share-buttons">
<button onclick="shareOnFacebook()">Share on Facebook</button>
<button onclick="shareOnTwitter()">Share on Twitter</button>
</div>
<script>
function shareOnFacebook() {
const url = encodeURIComponent(window.location.href);
window.open(`https://www.facebook.com/sharer/sharer.php?u=${url}`, '_blank');
}
function shareOnTwitter() {
const url = encodeURIComponent(window.location.href);
const text = encodeURIComponent(document.title);
window.open(`https://twitter.com/intent/tweet?url=${url}&text=${text}`, '_blank');
}
</script>
Add this code to your post layout or directly into your Markdown post using raw HTML. Customize the buttons and functions as needed.
Conclusion
Integrating social media sharing buttons into your Jekyll blog is straightforward and can greatly enhance your content's reach. Whether you choose a third-party service or custom code, making sharing easy encourages your readers to spread the word and helps grow your audience.