Skip to content

Commit ee7d778

Browse files
committed
feat: add WordPress integration guide and demo section
- Added a new 'WordPress Integration' section to index.html with step-by-step instructions. - Included PHP code snippets for enqueuing assets in unctions.php via standard WordPress hooks (wp_enqueue_scripts, wp_footer). - Implemented copy-to-clipboard functionality for the new code blocks. - Updated README.md to list WordPress as a formally supported platform. Fixes AOSSIE-Org#52, Fixes AOSSIE-Org#112
1 parent ea1aa48 commit ee7d778

2 files changed

Lines changed: 105 additions & 4 deletions

File tree

README.md

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Lightweight social sharing component for web applications. Zero dependencies, fr
7272

7373
- 🌐 Multiple platforms: WhatsApp, Facebook, X, LinkedIn, Telegram, Reddit, Email, Pinterest
7474
- 🎯 Zero dependencies - pure vanilla JavaScript
75-
- ⚛️ Framework support: React, Preact, Next.js, Qwik, Vue, Angular, or plain HTML
75+
- ⚛️ Framework support: React, Preact, Next.js, Qwik, Vue, Angular, WordPress or plain HTML
7676
- 🔄 Auto-detects current URL and page title
7777
- 📱 Fully responsive and mobile-ready
7878
- 🎨 Customizable themes (dark/light)
@@ -105,9 +105,9 @@ No matter which framework you use, integration always follows the same 3 steps:
105105

106106
| Step | What to do | Where |
107107
| -------------------- | ------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
108-
| **1️⃣ Load Library** | Add CSS + JS (CDN links) | Global layout file — `index.html` / `layout.tsx` / `_document.tsx` |
109-
| **2️⃣ Add Container** | Place `<div id="share-button"></div>` | The UI component where you want the button to appear |
110-
| **3️⃣ Initialize** | Call `new SocialShareButton({ container: "#share-button" })` | Inside that component, after the DOM is ready (e.g. `useEffect`, `mounted`, `ngAfterViewInit`) |
108+
| **1️⃣ Load Library** | Add CSS + JS (CDN links) | Global layout file — `index.html` / `layout.tsx` / `_document.tsx` / `functions.php` |
109+
| **2️⃣ Add Container** | Place `<div id="share-button"></div>` | The UI component or WordPress `wp_footer` hook |
110+
| **3️⃣ Initialize** | Call `new SocialShareButton({ container: "#share-button" })` | Inside that component or WordPress `wp_footer` hook |
111111

112112
> 💡 Pick your framework below for the full copy-paste snippet:
113113
@@ -486,6 +486,52 @@ export default function Header() {
486486
487487
</details>
488488
489+
<details>
490+
<summary><b>🔷 WordPress</b></summary>
491+
492+
### Step 1: Enqueue in `functions.php`
493+
494+
Add the following to your theme's `functions.php` to load the library from CDN:
495+
496+
```php
497+
function enqueue_social_share_button() {
498+
wp_enqueue_style(
499+
'social-share-button',
500+
'https://cdn.jsdelivr.net/npm/social-share-button/dist/social-share-button.css'
501+
);
502+
wp_enqueue_script(
503+
'social-share-button',
504+
'https://cdn.jsdelivr.net/npm/social-share-button/dist/social-share-button.js',
505+
[],
506+
null,
507+
true // Load in footer
508+
);
509+
}
510+
add_action('wp_enqueue_scripts', 'enqueue_social_share_button');
511+
```
512+
513+
### Step 2: Initialize in `functions.php` (Footer Hook)
514+
515+
You can use the `wp_footer` hook to inject the container and initialization script:
516+
517+
```php
518+
function init_social_share_button() { ?>
519+
<div id="share-button"></div>
520+
<script>
521+
new SocialShareButton({
522+
container: '#share-button',
523+
url: window.location.href,
524+
title: document.title,
525+
theme: 'dark',
526+
buttonText: 'Share'
527+
});
528+
</script>
529+
<?php }
530+
add_action('wp_footer', 'init_social_share_button');
531+
```
532+
533+
</details>
534+
489535
---
490536
491537
## Configuration

index.html

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,61 @@ <h2>⚛️ Preact Integration</h2>
476476
</code>
477477
</div>
478478
</div>
479+
480+
<!-- WordPress Integration -->
481+
<div class="demo-section">
482+
<h2>🔷 WordPress Integration</h2>
483+
<p>Integrate SocialShareButton into your WordPress theme without any extra plugins.</p>
484+
485+
<p><strong>Step 1:</strong> Enqueue the CSS and JS in <code>functions.php</code></p>
486+
<div class="code-block">
487+
<button type="button" class="copy-btn" aria-label="Copy code">Copy</button>
488+
<span
489+
class="copy-status"
490+
aria-live="polite"
491+
style="position: absolute; left: -9999px"
492+
></span>
493+
<code>
494+
function enqueue_social_share_button() {
495+
wp_enqueue_style(
496+
'social-share-button',
497+
'https://cdn.jsdelivr.net/npm/social-share-button/dist/social-share-button.css'
498+
);
499+
wp_enqueue_script(
500+
'social-share-button',
501+
'https://cdn.jsdelivr.net/npm/social-share-button/dist/social-share-button.js',
502+
[],
503+
null,
504+
true // Load in footer
505+
);
506+
}
507+
add_action('wp_enqueue_scripts', 'enqueue_social_share_button');</code>
508+
</div>
509+
510+
<p><strong>Step 2:</strong> Initialize the button in the footer</p>
511+
<div class="code-block">
512+
<button type="button" class="copy-btn" aria-label="Copy code">Copy</button>
513+
<span
514+
class="copy-status"
515+
aria-live="polite"
516+
style="position: absolute; left: -9999px"
517+
></span>
518+
<code>
519+
function init_social_share_button() { ?&gt;
520+
&lt;div id="share-button"&gt;&lt;/div&gt;
521+
&lt;script&gt;
522+
new SocialShareButton({
523+
container: '#share-button',
524+
url: window.location.href,
525+
title: document.title,
526+
theme: 'dark',
527+
buttonText: 'Share'
528+
});
529+
&lt;/script&gt;
530+
&lt;?php }
531+
add_action('wp_footer', 'init_social_share_button');</code>
532+
</div>
533+
</div>
479534
<!-- CTA Section -->
480535
<div class="cta-section">
481536
<h2 style="color: #fff; margin-bottom: 20px">Ready to Get Started?</h2>

0 commit comments

Comments
 (0)