Chia sẻ bài viết lên mạng xã hội
Mở file functions.php
trong child theme của bạn (nếu chưa có child theme, bạn nên tạo child theme để tránh mất thay đổi khi update theme). Thêm đoạn code sau:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
//Chia sẻ bài viết lên mạng xã hội function custom_social_share_buttons($content) { if (is_single() || is_page()) { $url = urlencode(get_permalink()); $title = urlencode(get_the_title()); $facebook = "https://www.facebook.com/sharer/sharer.php?u=$url"; $twitter = "https://x.com/intent/tweet?text=$title&url=$url"; $pinterest = "https://pinterest.com/pin/create/button/?url=$url&description=$title"; $messenger_web = "https://www.messenger.com/share?link=$url"; $messenger_mobile = "fb-messenger://share?link=$url"; $html = '<style> .custom-social-share { display: flex; align-items: center; gap: 10px; } .custom-social-share p { margin: 0; font-weight: bold; } .social-btn, .copy-link { font-size: 1em; text-decoration: none; border: none; background: none; cursor: pointer; } .zalo-share-button { transform-origin: center; } .copy-link { position: relative; top: 6px; } </style>'; $html .= '<div class="custom-social-share">'; $html .= '<p>Chia sẻ bài viết:</p>'; $html .= '<a href="' . $facebook . '" target="_blank" class="social-btn fb"><i class="fab fa-facebook-f"></i></a>'; $html .= '<a href="' . $twitter . '" target="_blank" class="social-btn x"><i class="fab fa-twitter"></i></a>'; $html .= '<a href="' . $pinterest . '" target="_blank" class="social-btn pin"><i class="fab fa-pinterest"></i></a>'; $html .= '<div class="zalo-share-button" data-href="' . get_permalink() . '" data-oaid="43280336123456" data-layout="1" data-color="blue" data-customize="false"></div>'; $html .= '<a href="' . $messenger_web . '" target="_blank" class="social-btn msg" onclick="openMessenger(event)"><i class="fab fa-facebook-messenger"></i></a>'; $html .= '<button class="copy-link" onclick="copyLink()"><i class="fas fa-link"></i></button>'; $html .= '</div>'; $html .= '<script src="https://sp.zalo.me/plugins/sdk.js"></script>'; $html .= '<script> function copyLink() { navigator.clipboard.writeText("' . get_permalink() . '"); alert("Link đã được copy!"); } function openMessenger(event) { event.preventDefault(); var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); var url = isMobile ? "' . $messenger_mobile . '" : "' . $messenger_web . '"; window.open(url, "_blank"); } </script>'; return $content . $html; } return $content; } add_filter('the_content', 'custom_social_share_buttons'); |
Thay data-oaid=”43280336123456″ bằng OA ID của bạn. Lấy tại https://developers.zalo.me/docs/social/share
Quý khách cần tư vấn thiết kế web giá rẻ, vui lòng nhấn nút bên dưới:
Chào ! Bạn thấy nội dung này thế nào?
Xem thêm:
- VDE Agency – Vượt trên sự hoàn hảo
- Hướng Dẫn Lưu Thông Tin Liên Hệ, Tin Nhắn Từ Contact Form 7 (CF7) Vào Database WordPress
- Hướng dẫn dùng Rclone sao lưu VPS qua Google Drive, One Drive,…
- Hướng dẫn Google nhận diện Tên trang web (Site Name) theo hướng dẫn từ Google
- Hướng dẫn code function kiểm tra chặn spam Contact Form 7 (CF7) dựa trên số lượng cuộn màn hình