Webflow sync, pageviews & more.
NEW

How can I create social sharing buttons/links on dynamic templates in Webflow using custom code and the method described by ( )?

TL;DR
  • Add dynamic CMS fields like slug, full URL, and title to your collection.
  • Insert an Embed block on the CMS template and create anchor tags using CMS fields to construct platform-specific share URLs.
  • Use full URLs and encode them properly; style links as buttons with classes or icons as needed.

To create dynamic social sharing buttons in Webflow using custom code, you can use the method where share URLs are constructed with dynamic CMS fields. This allows each CMS item (like a blog post) to generate its own social share links for platforms like Facebook, Twitter, or LinkedIn.

Here’s how to do it using Webflow’s CMS and custom embed code:

1. Add Dynamic CMS Fields for Sharing

  • Make sure your CMS collection has a Slug and a Full URL field (or use Webflow’s auto-generated slug with your site’s base URL).
  • You may also want the Post Title available in case it’s needed for Twitter or LinkedIn sharing.

2. Add an Embed Element to Your CMS Template

  • Inside your Collection Page Template, use a Webflow Embed block where you want the social buttons to appear.
  • Use custom HTML anchor tags within the embed, populating them with Webflow CMS fields.

3. Construct Share URLs Using CMS Field Values

In the Embed block, combine static share URLs with dynamic fields using the Add Field (+) button:

  • Facebook:
    <a href="https://www.facebook.com/sharer/sharer.php?u={{wf {&quot;path&quot;:&quot;slug&quot;,&quot;type&quot;:&quot;PlainText&quot;} }}">Share on Facebook</a>

  • Twitter:
    <a href="https://twitter.com/intent/tweet?url={{wf {&quot;path&quot;:&quot;slug&quot;,&quot;type&quot;:&quot;PlainText&quot;} }}&text={{wf {&quot;path&quot;:&quot;name&quot;,&quot;type&quot;:&quot;PlainText&quot;} }}">Tweet</a>

  • LinkedIn:
    <a href="https://www.linkedin.com/sharing/share-offsite/?url={{wf {&quot;path&quot;:&quot;slug&quot;,&quot;type&quot;:&quot;PlainText&quot;} }}">Share on LinkedIn</a>

Modify the CMS fields accordingly:

  • Replace slug with your full URL field if available.
  • Replace name with your title field for Twitter text.

4. Make Sure URLs Are Properly Encoded

  • Use full URLs for best results (e.g., https://yoursite.com/blog/{{slug}}).
  • You can construct this in a plain text field in your CMS called “Full Post URL” and use that in the embed.
  • Wrap the anchors (<a>) in divs or apply Webflow classes directly to the anchor tags.
  • Use Font Awesome or SVG icons for visual social icons next to the text if needed.

Summary

To add social share links on dynamic CMS templates, embed HTML share URLs with Webflow CMS fields injected via the Embed element. Combine dynamic slug or full URL fields to generate share links for Facebook, Twitter, and LinkedIn, ensuring each CMS item generates its own unique sharing link.

Rate this answer

Other Webflow Questions