Khi bạn tắt REST API trong WordPress, điều này có thể ảnh hưởng đến hoạt động của một số plugin, bao gồm Contact Form 7 (CF7), vì CF7 sử dụng REST API để xử lý các yêu cầu gửi form. Nếu REST API bị tắt, CF7 sẽ không thể hoạt động đúng cách, vì nó…
Lưu trữ danh mục: Thủ thuật
Plugin Contact Form 7 là một công cụ phổ biến để tạo biểu mẫu liên hệ trên các trang web WordPress. Tuy nhiên, theo mặc định, plugin này chỉ gửi thông tin liên hệ đến một địa chỉ email xác định và không lưu trữ dữ liệu trên trang web. Điều này có thể gây…
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 |
// Thêm nút phản ánh dưới mỗi bài post/page function add_feedback_button($content) { if (is_single() || is_page()) { $content .= '<button id="open-feedback-form" class="feedback-btn">Phản ánh bài viết</button>'; } return $content; } add_filter('the_content', 'add_feedback_button'); // Tạo popup chứa Contact Form 7 function feedback_popup_html() { ?> <div id="feedback-popup" class="feedback-popup"> <div class="feedback-content"> <span id="close-feedback" class="close-btn">×</span> <h3>Phản ánh bài viết</h3> <?php echo do_shortcode('[contact-form-7 id="123" title="Phản ánh bài viết"]'); ?> </div> </div> <style> .feedback-btn { background: #ff4d4d; color: white; padding: 10px 20px; border: none; cursor: pointer; display: block; margin: 20px auto; text-align: center; border-radius: 5px; } .feedback-popup { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); justify-content: center; align-items: center; z-index: 9999; } .feedback-content { background: white; padding: 20px; border-radius: 5px; text-align: center; width: 50%; position: relative; } .close-btn { position: absolute; top: 10px; right: 10px; font-size: 20px; cursor: pointer; } </style> <script> document.addEventListener("DOMContentLoaded", function () { var btn = document.getElementById("open-feedback-form"), popup = document.getElementById("feedback-popup"), close = document.getElementById("close-feedback"); if (btn && popup && close) { btn.addEventListener("click", () => popup.style.display = "flex"); close.addEventListener("click", () => popup.style.display = "none"); window.addEventListener("click", e => { if (e.target === popup) popup.style.display = "none"; }); } }); </script> <?php } add_action('wp_footer', 'feedback_popup_html'); |
Thay ID form CF7 (id=”123″) bằng ID form phản ánh của bạn. Lưu lại & kiểm tra: Khi vào bài post/page, bạn sẽ thấy…
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 |
//thông báo giờ đóng cửa add_action('wp_footer', 'webdy_store_hours_flatsome'); function webdy_store_hours_flatsome() { // Thiết lập múi giờ Việt Nam (UTC+7) date_default_timezone_set('Asia/Ho_Chi_Minh'); // Lấy giờ hiện tại (24h format) $current_hour = (int) date('H'); $current_minute = (int) date('i'); // Định nghĩa giờ mở và đóng cửa $open_hour = 8; // 8 AM $close_hour = 17; // 5 PM // Kiểm tra nếu ngoài giờ hoạt động (8 AM - 5 PM) $is_outside_hours = ($current_hour < $open_hour || $current_hour >= $close_hour); // Nếu ngoài giờ, ẩn các nút và hiển thị thông báo if ($is_outside_hours) { ?> <style> /* Ẩn nút Add to Cart trên trang sản phẩm */ .single_add_to_cart_button { display: none !important; } /* Ẩn nút Add to Cart trong vòng lặp sản phẩm (shop, category) */ .product .add_to_cart_button { display: none !important; } /* Ẩn nút Thanh toán ngay trên trang giỏ hàng */ .cart .checkout-button, .wc-proceed-to-checkout .checkout-button { display: none !important; } /* Ẩn nút Thanh toán ngay trong mini-cart (nếu có) */ .widget_shopping_cart .checkout { display: none !important; } </style> <script> jQuery(document).ready(function($) { // Thêm thông báo giờ đóng cửa với class "store-closed-notice" var notice = '<div class="store-closed-notice" style="background: #f8d7da; color: #721c24; padding: 15px; text-align: center; margin-bottom: 20px;">Webdy hiện đang đóng cửa. Giờ mở cửa: 8:00 AM - 5:00 PM.</div>'; // Thêm thông báo vào trang sản phẩm if ($('.single-product').length) { $('.product-main').prepend(notice); } // Thêm thông báo vào trang shop/category if ($('.shop-page').length) { $('.shop-container').prepend(notice); } // Thêm thông báo vào trang giỏ hàng if ($('.cart').length) { $('.cart').prepend(notice); } }); </script> <?php } } |
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
Bạn có thể thiết lập thông báo Telegram khi có ai đó sửa đổi hoặc thêm tệp trong thư mục WordPress bằng cách sử dụng một script PHP kết hợp với webhook của Telegram và inotifywait (trên Linux). Cách thực hiện: Tạo bot Telegram và lấy token Vào @BotFather trên Telegram. Gõ lệnh /newbot và…
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 |
// Hàm lấy số lượng Like hoặc Dislike function ip_get_like_count($type = 'likes') { $current_count = get_post_meta(get_the_id(), $type, true); return ($current_count ? $current_count : 0); } // Hàm xử lý Like và Dislike function ip_process_like() { if (is_singular('post')) { if (isset($_GET['post_action']) && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'ip_like_action')) { $processed_like = false; $redirect = false; // Kiểm tra hành động Like hoặc Dislike if ($_GET['post_action'] == 'like') { $like_count = get_post_meta(get_the_id(), 'likes', true); $like_count = $like_count ? $like_count + 1 : 1; $processed_like = update_post_meta(get_the_id(), 'likes', $like_count); } elseif ($_GET['post_action'] == 'dislike') { $dislike_count = get_post_meta(get_the_id(), 'dislikes', true); $dislike_count = $dislike_count ? $dislike_count + 1 : 1; $processed_like = update_post_meta(get_the_id(), 'dislikes', $dislike_count); } if ($processed_like) { $redirect = get_the_permalink(); // Trả về trang bài viết sau khi cập nhật } if ($redirect) { wp_redirect($redirect); // Tải lại trang để hiển thị kết quả mới die; } } } } add_action('template_redirect', 'ip_process_like'); |
CSS tí cho đẹp
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 |
/* CSS nút hữu ích */ .ok-like a { margin-right: 10px; text-decoration: none; color: #111; font-size: 13px; font-weight: bold; background: #fff444; padding: 5px 8px 5px 8px; border-radius: 7px; display: inline-block; } .ok-like a:hover { color: #fff; background: #0c0; } .title-like { color: #ccc; font-size: 15px; } .yes-likes { padding: 20px; background: #4b238a; text-align: center; border-radius: 10px; } @media (max-width: 400px) { .ok-like a { font-size: 10px; } } /*---------------------------------------------*/ |
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 |
// chặn bình luận chứa liên kết function webdy_block_links_in_comments($comment_content) { $pattern = '/\b(?:https?|ftp):\/\/[^\s]+/i'; if (preg_match($pattern, $comment_content)) { wp_die(__('Bình luận của bạn đã bị chặn bởi Webdy. Vui lòng không đăng liên kết!', 'webdy-text-domain')); } return $comment_content; } add_filter('pre_comment_content', 'webdy_block_links_in_comments'); |
Cài Đặt RCLONE Cài đặt RCLONE bản mới nhất với bất kỳ hệ điều hành nào:
1 |
curl https://rclone.org/install.sh | sudo bash |
Ngoài ra bạn cũng có thể tham khảo ở trang chủ của RCLONE tại đây RCLONE một số lệnh cơ bản rclone config – Cấu hình kết nối đến dịch vụ cloud. rclone copy – Copy files từ server…
Thêm đoạn code sau vào file functions.php:
1 2 3 4 |
function wpvn_no_meta_viewport() { return false; } add_filter( 'flatsome_viewport_meta', 'wpvn_no_meta_viewport' ); |