<?php
// Add custom Theme Functions here
function add_equal_heights_script() {
?>
<script type="text/javascript">
(function() {
// Configuration: Change this to your specific class
const targetClass = '.box.san-pham-noi-bat';
function setEqualHeights(selector) {
const elements = document.querySelectorAll(selector);
let maxHeight = 0;
// 1. Reset heights
elements.forEach(el => el.style.height = 'auto');
// 2. Measure heights
elements.forEach(el => {
if (el.offsetHeight > maxHeight) {
maxHeight = el.offsetHeight;
}
});
// 3. Apply max height
elements.forEach(el => el.style.height = `${maxHeight}px`);
}
// Run on load and resize
window.addEventListener('load', () => setEqualHeights(targetClass));
window.addEventListener('resize', () => setEqualHeights(targetClass));
})();
</script>
<?php
}
add_action('wp_footer', 'add_equal_heights_script');
if (function_exists('acf_add_options_page')) {
acf_add_options_page(array(
'page_title' => 'Cài đặt website',
'menu_title' => 'Cài đặt website',
'menu_slug' => 'website-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}
function preload_links_on_hover() {
?>
<script>
document.addEventListener("DOMContentLoaded", function () {
const links = document.querySelectorAll("a[href]");
links.forEach(link => {
link.addEventListener("mouseenter", function () {
const href = link.getAttribute("href");
if (!href.startsWith("http") || href.includes(window.location.hostname)) {
const linkTag = document.createElement("link");
linkTag.rel = "prefetch";
linkTag.href = href;
linkTag.as = "document";
document.head.appendChild(linkTag);
}
});
});
});
</script>
<?php
}
add_action('wp_footer', 'preload_links_on_hover');
add_filter( 'wpseo_json_ld_output', '__return_false' );
/**
* Add CreativeWorkSeries Schema to all pages
*/
add_action( 'wp_head', 'gb_add_creative_work_schema_sitewide' );
function gb_add_creative_work_schema_sitewide() {
?>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "CreativeWorkSeries",
"@id": "https://giftbusiness.vn/#creativeworkseries",
"name": "Quà tặng doanh nghiệp GIFT BUSINESS, In logo quà tặng",
"url": "https://giftbusiness.vn/",
"inLanguage": "vi-VN",
"description": "Nhà cung cấp quà tặng doanh nghiệp uy tín, chuyên sản xuất và cung cấp quà tặng in logo công ty, quà tặng khách hàng, quà tặng sự kiện, quà tặng công nghệ độc đáo. Với gần 10 năm kinh nghiệm, Gift Business mang đến giải pháp quà tặng in logo thương hiệu cho doanh nghiệp trên toàn quốc, đồng thời chia sẻ kiến thức và kinh nghiệm chuyên sâu trong lĩnh vực quà tặng doanh nghiệp.",
"creator": {
"@type": "Organization",
"name": "CÔNG TY QUÀ TẶNG GIFT BUSINESS",
"url": "https://giftbusiness.vn",
"logo": {
"@type": "ImageObject",
"url": "https://giftbusiness.vn/wp-content/uploads/2022/09/GIFTBUSINESS-FINAL.png"
}
},
"publisher": {
"@type": "Organization",
"name": "CÔNG TY QUÀ TẶNG GIFT BUSINESS",
"url": "https://giftbusiness.vn",
"logo": {
"@type": "ImageObject",
"url": "https://giftbusiness.vn/wp-content/uploads/2022/09/GIFTBUSINESS-FINAL.png"
}
},
"hasPart": [
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/danh-muc-san-pham/binh-giu-nhiet-in-logo/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/danh-muc-san-pham/dong-ho-treo-tuong/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/danh-muc-san-pham/qua-tang-cong-nghe/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/danh-muc-san-pham/qua-tang-khach-hang/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/danh-muc-san-pham/qua-tang-su-kien/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/danh-muc-san-pham/set-qua-tang-doanh-nghiep/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/danh-muc-san-pham/qua-tang-quang-cao/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/danh-muc-san-pham/qua-tang-vip/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/danh-muc-san-pham/qua-tet-doanh-nghiep/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/qua-tang-8-3-ngay-quoc-te-phu-nu/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/stt-cuoc-song-y-nghia/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/lam-lich-de-ban/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/qua-tang-cao-cap-sang-trong/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/o-du-in-logo-gia-re/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/set-qua-tang-20-10-doc-dao/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/qua-tang-doanh-nhan-cao-cap/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/qua-tang-doanh-nghiep-vip/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/in-lich-de-ban/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/qua-tang-ky-niem-thanh-lap-cong-ty/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/qua-tang-hoi-nghi-khach-hang/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/qua-tang-tri-an-khach-hang/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/qua-tang-doanh-nghiep-y-nghia/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/qua-tang-khach-hang-nu/" },
{ "@type": "CreativeWork", "url": "https://giftbusiness.vn/tin-tuc/qua-tang-doanh-nghiep-doc-dao/" }
]
}
</script>
<?php
}
add_action('wp_head', 'add_localbusiness_schema');
function add_localbusiness_schema() {
?>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Công Ty Quà Tặng Doanh Nghiệp GIFT BUSINESS",
"description": "GIFT BUSINESS chuyên cung cấp quà tặng doanh nghiệp cao cấp, thiết kế theo yêu cầu và giao hàng toàn quốc.",
"image": "https://giftbusiness.vn/wp-content/uploads/2025/07/logo-vuong-1-1.png",
"logo": "https://giftbusiness.vn/wp-content/uploads/2025/07/logo-vuong-1-1.png",
"@id": "",
"url": "https://giftbusiness.vn/",
"telephone": "02822138900",
"address": {
"@type": "PostalAddress",
"streetAddress": "49 Đường 17, Khu Dân Cư Nam Long, Phường Phước Long, TP. Hồ Chí Minh",
"addressRegion": "SG",
"addressLocality": "Hồ Chí Minh",
"postalCode": "700000",
"addressCountry": "VN"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": "10.8085313",
"longitude": "106.7785113"
},
"sameAs": [
"https://www.facebook.com/GIFTBUSINESS/",
"https://www.instagram.com/giftbusinessvn/",
"https://www.youtube.com/@giftbusiness-ChannelOfficial",
"https://www.pinterest.com/giftbusinessvn/"
],
"openingHoursSpecification": [
{
"@type": "OpeningHoursSpecification",
"dayOfWeek": [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday"
],
"opens": "08:00",
"closes": "17:00"
},
{
"@type": "OpeningHoursSpecification",
"dayOfWeek": "Saturday",
"opens": "08:00",
"closes": "12:00"
}
],
"priceRange": "$$",
"currenciesAccepted": "VND",
"paymentAccepted": "Cash, Credit Card, Bank Transfer"
}
</script>
<?php
}
add_action('wp_head', 'add_schema_person_jsonld');
function add_schema_person_jsonld() {
?>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Person",
"name": "Nguyễn Bửu Thạch",
"jobTitle": "Giám đốc điều hành Công Ty Quà Tặng GIFT BUSINESS",
"url": "https://giftbusiness.vn/founder-gift-business/",
"image": "https://giftbusiness.vn/wp-content/uploads/2025/08/z5921311895272_0a8cb5192ece58d11bd9471bdda292d7.jpg",
"sameAs": [
"https://www.facebook.com/thach.nguyen.9889261/"
],
"worksFor": {
"@type": "Organization",
"name": "https://giftbusiness.vn/"
}
}
</script>
<?php
}
if (!function_exists('az_wp_enqueue_script')):
function az_wp_enqueue_script()
{
wp_enqueue_style('slick-css', get_stylesheet_directory_uri() . '/slick/slick.css');
wp_enqueue_style('slick-theme', get_stylesheet_directory_uri() . '/slick/slick-theme.css');
wp_enqueue_script('slick-js', get_stylesheet_directory_uri() . '/slick/slick.js', array(), '1.0.0', true);
wp_enqueue_script('jsthem', get_stylesheet_directory_uri() . '/chayweb.js', array(), '1.0.0', true);
wp_enqueue_script('countjs', get_stylesheet_directory_uri() . '/count/numscroller-1.0.js', array(), '1.0.0', true);
wp_enqueue_script('countjss', get_stylesheet_directory_uri() . '/count/lib/prism.js', array(), '1.0.0', true);
}
add_action('wp_enqueue_scripts', 'az_wp_enqueue_script', 1);
endif;
if (!function_exists('get_homeslider')) {
function get_homeslider(){
$galle = get_field('home_gallery','option');
ob_start();
if(!empty($galle)):
?>
<div class="home_slider galleyr_1">
<div class="centerss">
<?php foreach($galle as $item): ?>
<a href="<?= $item['link']; ?>" target="_blank">
<div class="box_img">
<div class="image-cover" style="padding-top: 100%;">
<img src="<?= $item['img']['url']; ?>" alt="<?= $item['img']['alt']; ?>">
</div>
<span class="image-title"><?= $item['title']; ?></span>
</div>
</a>
<?php endforeach; ?>
</div>
</div>
<?php
endif;
$list_post = ob_get_contents();
ob_end_clean();
return $list_post;
}
add_shortcode('eget_homeslider', 'get_homeslider');
}
if (!function_exists('get_danhmuc')) {
function get_danhmuc(){
$galle = get_field('home_danh_muc','option');
ob_start();
if(!empty($galle)):
?>
<div class="home_danhmuc row large-columns-6 medium-columns-3 small-columns-2">
<?php foreach($galle as $key => $item): ?>
<div class="gallery-col col">
<div class="col-inner">
<a class="" href="<?= $item['link'];?>" title="">
<div class="box has-hover gallery-box box-shade dark box-text-middle">
<div class="box-image image-zoom" style="border-radius:100%;">
<img width="300" height="300" src="<?= $item['img']['url'];?>" >
<div class="shade"></div>
</div>
<div class="box-text text-center">
<h3><?= $item['title'];?></h3>
</div>
</div>
</a>
</div>
</div>
<?php endforeach; ?>
</div>
<?php
endif;
$list_post = ob_get_contents();
ob_end_clean();
return $list_post;
}
add_shortcode('eget_danhmuc', 'get_danhmuc');
}
if (!function_exists('get_dv')) {
function get_dv(){
ob_start();
$dv = get_posts(
array(
'post_type' => 'post',
'posts_per_page' => 4,
'category_name' => 'dich-vu-qua-tang'
// 'category_name' => 'dich-vu'
)
);
if(!empty($dv)):
?>
<div class="list_dv">
<?php foreach($dv as $key => $post): ?>
<div class="gallery-col">
<div class="col-inner">
<div class="box row row-collapse">
<div class="col large-6">
<div class="box-image">
<div class="image-cover " style="padding-top: 100%;">
<img width="300" height="300" src="<?= get_the_post_thumbnail_url($post->ID,'large'); ?>">
</div>
</div>
</div>
<div class="col large-5">
<div class="box-text ">
<h3><?= get_the_title($post->ID); ?></h3>
<div class="desc">
<?= get_the_excerpt($post->ID);?>
</div>
<a class="button primary" href="<?= get_permalink($post->ID);?>" style="border-radius:99px;padding:0px 45px 0px 21px; display: inline-block;">
<span>Xem thêm</span>
</a>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php
endif;
$list_post = ob_get_contents();
ob_end_clean();
return $list_post;
}
add_shortcode('eget_dv', 'get_dv');
}
if (!function_exists('get_listks')) {
function get_listks(){
ob_start();
?>
<div class="list_kh" id="counter">
<div class="item item-1">
<div class="i_1"><span>+</span><span class="stt numscroller" data-min='1' data-max='500' data-delay='15' data-increment='10'>0</span></div>
<div class="des">Khách hàng đã hài lòng</div>
</div>
<div class="item item-2">
<div class="i_1"><span>+</span><span class="stt numscroller" data-min='1' data-max='99' data-delay='15' data-increment='10'>0</span><span>%</span></div>
<div class="des">Giao hàng đúng hẹn</div>
</div>
</div>
<div class="list_kh">
<div class="item item-3">
<div class="i_2"><span>+</span><span class="stt numscroller" data-min='1' data-max='2000' data-delay='15' data-increment='10'>0</span></div>
<div class="des">Đơn hàng đã thực hiện</div>
</div>
<div class="item item-4">
<div class="i_2"><span>+</span><span class="stt numscroller" data-min='1' data-max='100' data-delay='15' data-increment='10'>0</span></div>
<div class="des">Thành tựu khác</div>
</div>
</div>
<?php
$list_post = ob_get_contents();
ob_end_clean();
return $list_post;
}
add_shortcode('eget_listks', 'get_listks');
}
if (!function_exists('get_tt')) {
function get_tt(){
ob_start();
$posts = get_posts(
array(
'post_type' => 'post',
'posts_per_page' => 4,
'category_name' => 'tin-tuc'
)
);
if(!empty($posts)):
?>
<div class="list_tintuc">
<?php foreach($posts as $key => $post): ?>
<div class="post_item">
<div class="imgs_s" style="position: relative; padding-top: 120px;">
<div class="box_img">
<div class="image-cover" style=" padding-top: 100%;">
<img width="300" height="300" src="<?= get_the_post_thumbnail_url($post->ID,'large'); ?>">
</div>
</div>
</div>
<div class="box_info">
<div class="i_meta">
<div class="date"><?= get_the_time('d',$post->ID); ?></div>
<div class="mon-y"><?= get_the_time('M , Y',$post->ID); ?></div>
</div>
<div class="i_info">
<h3><?= get_the_title($post->ID); ?></h3>
<div class="desc">
<?= get_the_excerpt($post->ID);?>
</div>
<div class="text-center">
<a class="button primary" href="<?= get_permalink($post->ID);?>" style="border-radius:99px;padding:0px 45px 0px 21px; display: inline-block;">
<span>Xem thêm</span> </a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php
endif;
$list_post = ob_get_contents();
ob_end_clean();
return $list_post;
}
add_shortcode('eget_tt', 'get_tt');
}
function your_function() {
?>
<div id="baogia" class="lightbox-by-id lightbox-content mfp-hide lightbox-white">
<div class="text-inner text-center" onmouseenter="autoFillProductName();">
<h3 class="uppercase"><strong>Quý khách vui lòng hoàn thành form dưới đây để nhận tư vấn hoặc báo giá:</strong></h3>
<?= do_shortcode('[contact-form-7 id="278" title="Báo giá"]');?>
</div>
</div>
<script>
function autoFillProductName() {
if (jQuery('h1.product-title.product_title.entry-title').length) {
var tensp = jQuery('h1.product-title.product_title.entry-title').text();
tensp = tensp.trim();
if (jQuery('#baogia').is('visible')) {
jQuery('input[name="your-loaihanghoa"]').val(tensp);
}
}
}
</script>
<?php }
add_action( 'wp_footer', 'your_function' );
function your_function1() {
$sideba_s = get_field('thong_tin_cong_ty','option');
if(!empty($sideba_s)):
?>
<div class="echbay-sms-messenger style-for-position-br">
<div class="phonering-alo-alo">
<a href="tel:<?= $sideba_s['hotline'];?>" rel="nofollow"><img src="<?= get_stylesheet_directory_uri();?>/images/call.png"><span><?= $sideba_s['hotline'];?></span></a>
</div>
</div>
<?php
endif;
}
add_action( 'wp_footer', 'your_function1' );
// function extend_nonce_lifetime_test() {
// return 12 * HOUR_IN_SECONDS;
// }
// add_filter( 'nonce_life', 'extend_nonce_lifetime_test' );
//
function custom_mobile_bottom_menu() {
?>
<div class="mobile-bottom-menu">
<a href="<?php echo esc_url(home_url()); ?>" class="menu-item">
<i class="fas fa-home"></i>
<span>Trang chủ</span>
</a>
<div class="menu-item has-submenu" id="shop-menu-btn">
<i class="fas fa-bars"></i>
<span>Danh mục</span>
</div>
<div class="shop-submenu" id="shop-submenu" style="display: none;">
<?php
// Hàm hiển thị danh mục THEO ĐÚNG THỨ TỰ ADMIN (drag & drop)
function display_product_categories_like_admin($parent_id = 0, $depth = 0) {
$args = array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'parent' => $parent_id,
'orderby' => 'term_order', // Quan trọng: theo thứ tự kéo thả
'order' => 'ASC',
);
$terms = get_terms($args);
if (!empty($terms) && !is_wp_error($terms)) {
// Mở ul chỉ khi có danh mục
echo '<ul class="mobile-cat-level' . ($depth === 0 ? ' root-level' : '') . '">';
foreach ($terms as $term) {
$link = get_term_link($term);
$indent = $depth > 0 ? str_repeat(' ', $depth) : ''; // Dấu gạch ngang theo depth
$cat_name = $indent . esc_html($term->name);
echo '<li>';
echo '<a href="' . esc_url($link) . '">' . $cat_name . '</a>';
// Đệ quy: hiển thị con theo đúng thứ tự
display_product_categories_like_admin($term->term_id, $depth + 1);
echo '</li>';
}
echo '</ul>';
}
}
// Bắt đầu từ danh mục gốc
display_product_categories_like_admin();
?>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const btn = document.getElementById('shop-menu-btn');
const submenu = document.getElementById('shop-submenu');
if (btn && submenu) {
btn.addEventListener('click', function(e) {
e.stopPropagation();
submenu.style.display = submenu.style.display === 'none' ? 'block' : 'none';
});
// Đóng khi click ngoài
document.addEventListener('click', function(e) {
if (!btn.contains(e.target) && !submenu.contains(e.target)) {
submenu.style.display = 'none';
}
});
// Đóng khi click vào link
submenu.querySelectorAll('a').forEach(link => {
link.addEventListener('click', function() {
submenu.style.display = 'none';
});
});
}
});
</script>
<style>
/*
.mobile-bottom-menu {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background: #fff;
display: flex;
justify-content: space-around;
align-items: center;
border-top: 1px solid #eee;
z-index: 9999;
padding: 6px 0;
box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.mobile-bottom-menu .menu-item {
text-align: center;
font-size: 13px;
color: #333;
flex: 1;
padding: 5px 0;
cursor: pointer;
user-select: none;
}
.mobile-bottom-menu .menu-item i {
display: block;
font-size: 18px;
margin-bottom: 2px;
}
.shop-submenu {
position: fixed;
bottom: 64px;
left: 0;
width: 100%;
background: #fff;
box-shadow: 0 -2px 15px rgba(0,0,0,0.1);
padding: 15px;
max-height: 50vh;
overflow-y: auto;
border-top: 1px solid #eee;
z-index: 9998;
}
.mobile-cat-level {
list-style: none;
padding: 0;
margin: 0 0 0 8px;
}
.mobile-cat-level.root-level {
margin-left: 0;
}
.mobile-cat-level li {
margin-bottom: 6px;
line-height: 1.4;
}
.mobile-cat-level a {
text-decoration: none;
color: #222;
font-size: 14px;
display: block;
padding: 4px 0;
}
.mobile-cat-level a:hover {
color: #ff6600;
}
.mobile-cat-level li:has(> ul) > a::before {
content: "▶ ";
font-size: 10px;
opacity: 0.6;
margin-right: 2px;
} */
</style>
<?php
}
add_action('wp_footer', 'custom_mobile_bottom_menu');
function new_tab_inline_js_footer() {
?>
<script>
document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll(
".danh-muc-san-pham-trang-chu .product-category a"
).forEach(function (link) {
link.setAttribute("target", "_blank");
link.setAttribute("rel", "noopener noreferrer");
});
});
</script>
<?php
}
add_action('wp_footer', 'new_tab_inline_js_footer');
add_filter('do_shortcode_tag', function ($output, $tag) {
if ($tag === 'ux_product_categories') {
// Đổi h5.header-title thành h2.header-title
$output = preg_replace(
'/<h5([^>]*)class="([^"]*header-title[^"]*)"([^>]*)>/i',
'<h2$1class="$2"$3>',
$output
);
$output = preg_replace(
'/<\/h5>/i',
'</h2>',
$output
);
}
return $output;
}, 10, 2);
add_action('wp_footer', 'flatsome_collapse_category_description');
function flatsome_collapse_category_description() {
// Chỉ chạy trên trang danh mục sản phẩm (Product Category)
if ( ! is_product_category() ) return;
?>
<style>
a.button.primary.expand-content-btn {
display: inline-flex;
align-items: center;
}
a.button.primary.expand-content-btn:before {
transform: rotate(90deg);
}
a.button.primary.expand-content-btn.less:before {
transform: rotate(270deg);
}
</style>
<script type="text/javascript">
jQuery(document).ready(function($) {
// CẤU HÌNH
var show_char = 1000; // Số lượng từ (ước lượng) hoặc chiều cao muốn hiển thị
var ellipsestext = "...";
var moretext = "Xem thêm";
var lesstext = "Thu gọn";
// Chọn vùng nội dung cần thu gọn trong Flatsome
// .term-description: Mô tả mặc định (trên cùng)
// .cat-footer: Mô tả dưới đáy (Bottom content - thường dùng cho SEO)
var target = $('.term-description, .page-header-info-content, .cat-footer');
target.each(function() {
var content = $(this).html();
// Cách 1: Giới hạn theo chiều cao (Pixel) - Cách này ĐẸP NHẤT cho Flatsome
// Vì Flatsome layout rất đa dạng, đếm từ có thể làm vỡ khung
var max_height = 900; // Chiều cao tối đa khi thu gọn (px)
if ($(this).height() > max_height) {
$(this).css({
'height': max_height + 'px',
'overflow': 'hidden',
'position': 'relative',
'transition': 'height 0.3s ease'
});
// Thêm hiệu ứng mờ dần ở đáy
$(this).append('<div class="readmore-overlay" style="position: absolute; bottom: 0; left: 0; width: 100%; height: 50px; background: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255,1));"></div>');
// Thêm nút xem thêm
$(this).after('<div class="readmore-wrap" style="text-align: center; margin-top: 10px;"><a href="javascript:void(0)" class="button primary box-shadow-3 expand-content-btn" style="border-radius: 99px;">' + moretext + '</a></div>');
}
});
// Xử lý sự kiện click
$('body').on('click', '.expand-content-btn', function() {
var contentBox = $(this).parent().prev(); // Lấy thẻ div nội dung ngay trước nút
var overlay = contentBox.find('.readmore-overlay');
if ($(this).hasClass('less')) {
// Đang mở -> Thu lại
$(this).removeClass('less');
$(this).html(moretext);
contentBox.css('height', '900px'); // Thu về chiều cao cũ
overlay.show(); // Hiện lại lớp mờ
// Cuộn nhẹ lên đầu đoạn văn để người dùng không bị lạc
$('html, body').animate({
scrollTop: contentBox.offset().top - 100
}, 500);
} else {
// Đang đóng -> Mở ra
$(this).addClass('less');
$(this).html(lesstext);
contentBox.css('height', 'auto'); // Mở full chiều cao
overlay.hide(); // Ẩn lớp mờ
}
});
});
</script>
<?php
}