Chính Sách Cookie 1

Chính Sách Cookie

Thêm Chính Sách Cookie Cho Web Wordpress

  • Một code ngắn chèn vào web làm cho web chuyên nghiệp hơn một chút, hiển thị 1 popup hỏi về chính sách cookie, nếu người dùng chưa bấm đồng ý thì sẽ hiện popup. Sau khi bấm, popup sẽ ẩn vĩnh viễn trên trình duyệt đó.
  • Gọn nhẹ: Tải trực tiếp ở footer, không làm chậm tốc độ load trang (Core Web Vitals).
  • Lưu trạng thái bằng localStorage: Nhẹ hơn cookie thuần và lưu vô thời hạn cho đến khi người dùng xóa bộ nhớ cache trình duyệt.
  • Tương thích Responsive: Tự động điều chỉnh giao diện đẹp mắt trên cả máy tính và điện thoại.
Miễn phí
Version v1.0.0
Cập nhật 27/08/2026

Nội dung chi tiết

Gọi ngay để nhận giá tốt

Hướng dẫn : Dùng Plugin Code Snippets >> + Add Snippet >> chọn Add Your Custom Code >> chọn PHP Snippets >>  đặt tiêu đề rồi dán đoạn code dưới vào, lưu lại, xóa lịch sử là xong

Chính Sách Cookie cho website php
add_action('wp_footer', function() {
?>
<div id="cookie-consent-popup" class="cookie-popup">
<div class="cookie-popup-content">
<p>Website sử dụng cookie để cải thiện trải nghiệm của bạn. Bằng việc tiếp tục truy cập, bạn đồng ý với việc sử dụng cookie của chúng tôi.</p>
<button id="accept-cookie-btn" class="cookie-btn">Đồng ý</button>
</div>
</div>

<style>
.cookie-popup {
position: fixed;
bottom: -100px;
left: 20px;
right: 20px;
max-width: 450px;
background: #ffffff;
color: #333333;
padding: 18px 20px;
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
z-index: 999999;
transition: all 0.4s ease-in-out;
opacity: 0;
visibility: hidden;
font-family: inherit;
}
.cookie-popup.show {
bottom: 20px;
opacity: 1;
visibility: visible;
}
.cookie-popup-content {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
}
.cookie-popup p {
margin: 0;
font-size: 13.5px;
line-height: 1.5;
color: #4a5568;
}
.cookie-btn {
background-color: #2563eb;
color: #ffffff;
border: none;
padding: 8px 18px;
font-size: 13px;
font-weight: 600;
border-radius: 6px;
cursor: pointer;
white-space: nowrap;
transition: background-color 0.2s ease;
}
.cookie-btn:hover {
background-color: #1d4ed8;
}
@media (max-width: 480px) {
.cookie-popup-content {
flex-direction: column;
align-items: flex-start;
}
.cookie-btn {
width: 100%;
}
}
</style>

<script>
document.addEventListener('DOMContentLoaded', function() {
const popup = document.getElementById('cookie-consent-popup');
const btn = document.getElementById('accept-cookie-btn');

if (!localStorage.getItem('cookie_accepted')) {
setTimeout(function() {
popup.classList.add('show');
}, 1000); // Hiện sau 1 giây
}

btn.addEventListener('click', function() {
localStorage.setItem('cookie_accepted', 'true');
popup.classList.remove('show');
});
});
</script>
<?php
});

Tài nguyên liên quan

Để lại một bình luận