// Ẩn top bar admin // function hide_admin_bar(){ return false; } // add_filter( 'show_admin_bar', 'hide_admin_bar' ); add_filter('flatsome_lightbox_close_btn_inside', '__return_true'); // Thêm các file css, js function add_theme_scripts_client() { $ver = "1.1"; wp_enqueue_style('custom-css', get_template_directory_uri() . '-child' . '/customs/style.css', array(), $ver, 'all'); } add_action('wp_enqueue_scripts', 'add_theme_scripts_client'); // Button trang chi tiết sản phẩm function add_button_product_detail() { $html = ''; if (is_singular('product')) { $linkDownload = get_field('link_download_hdsd') ? get_field('link_download_hdsd') : '#popup-form'; $html = '<div id="button-product-detail"> <a href="#popup-form" class="button alert is-larger lowercase animate-scale" style="border-radius: 100px;"><span>Nhận báo giá</span></a> <a href="'.$linkDownload.'" class="button is-larger lowercase animate-scale disable-color" style="border-radius: 100px;"><span>Hướng dẫn sử dụng</span></a> </div>'; } echo $html; } add_action('flatsome_custom_single_product_1', 'add_button_product_detail'); // Config số lượng sản phẩm liên quan function change_number_related_products( $args ) { $args['posts_per_page'] = 4; return $args; } add_filter( 'woocommerce_output_related_products_args', 'change_number_related_products', 20 ); // Custom section sản phẩm liên quan function custom_related_product() { $html = ''; if (is_singular('product')) { global $product; $link = $product->get_permalink(); $sku = $product->get_sku() ? $product->get_sku() : 'N/A'; $category = get_the_terms( $product->get_id(), 'product_cat' ) ? get_the_terms( $product->get_id(), 'product_cat' )[0]->name : 'N/A'; $size = $product->get_attribute( 'kich-co' ) ? $product->get_attribute( 'kich-co' ) : 'N/A'; $excaly = $product->get_attribute( 'do-chinh-xac' ) ? $product->get_attribute( 'do-chinh-xac' ) : 'N/A' ; $html = '<div class="button-wrapper"> <a href="'.$link.'" class="button alert is-larger lowercase" style="border-radius: 100px;"><span>Xem thêm</span></a> </div> <ul class="config-wrapper"> <li> <span class="icon"><img src="'.home_url() .'/' . 'wp-content/uploads/2021/07/point.png'.'" alt=""></span> <span class=config-value>Models: '.$sku.'</span> </li> <li> <span class="icon"><img src="'.home_url() .'/' . 'wp-content/uploads/2021/07/point.png'.'" alt=""></span> <span class=config-value>'.$category.'</span> </li> <li> <span class="icon"><img src="'.home_url() .'/' . 'wp-content/uploads/2021/07/point.png'.'" alt=""></span> <span class=config-value>Kích cỡ: '.$size.'</span> </li> <li> <span class="icon"><img src="'.home_url() .'/' . 'wp-content/uploads/2021/07/point.png'.'" alt=""></span> <span class=config-value>Độ chính xác: '.$excaly.'</span> </li> </ul> '; } echo $html; } add_action('flatsome_product_box_after','custom_related_product'); // Remove tab đánh giá trong chi tiết sản phẩm function remove_product_tabs( $tabs ) { if (is_singular('product')) { unset( $tabs['reviews'] ); } return $tabs; } add_filter( 'woocommerce_product_tabs', 'remove_product_tabs', 98 ); // Add thêm tab trong chi tiết sản phẩm function add_new_product_tab( $tabs ) { if (is_singular('product')) { $tabs['configs_tab'] = array( 'title' => __( 'Thông số kỹ thuật', 'woocommerce' ), 'priority' => 50, 'callback' => 'add_content_configs_tab' ); $tabs['certifications_tab'] = array( 'title' => __( 'Chứng chỉ sản phẩm', 'woocommerce' ), 'priority' => 50, 'callback' => 'add_content_certifications_tab' ); $tabs['accessaries_tab'] = array( 'title' => __( 'Phụ kiện', 'woocommerce' ), 'priority' => 50, 'callback' => 'add_content_accessaries_tab' ); } return $tabs; } add_filter( 'woocommerce_product_tabs', 'add_new_product_tab' ); // Tab thông số kĩ thuật function add_content_configs_tab() { $content = get_field('configs_tab_detail'); if ($content) { echo $content; } else { echo "<p>Đang cập nhật...</p>"; } } // Tab chứng chỉ function add_content_certifications_tab() { $images = get_field('certifications_tab_img'); $html = ''; if ($images) { $html = '<ul id="tab-cretification-img">'; foreach( $images as $img ) { $html .= '<li><img src="'.esc_url($img['sizes']['thumbnail']).'" alt="'.esc_attr($img['alt']).'" /></li>'; } $html .= '</ul>'; } else { echo "<p>Đang cập nhật...</p>"; } echo $html; } // Tab phụ kiện function add_content_accessaries_tab() { $content = get_field('accessaries_tab_detail'); if ($content) { echo $content; } else { echo "<p>Đang cập nhật...</p>"; } } // Tiêu đề trang danh mục sản phẩm function add_title_category_name() { $title = ''; // Lấy info danh mục global $wp_query; $cat = $wp_query->get_queried_object(); if (is_product_category() && $cat->name) { $title = '<h2 id="category-name" class="text-center">'.$cat->name.'</h2>'; } echo $title; } add_action('woocommerce_before_main_content','add_title_category_name'); // Lấy mã sản phẩm trang danh mục function get_sku_category_product() { $html = ''; if (is_product_category() || is_shop()) { global $product; $title = $product->get_sku() ? $product->get_sku() : $product->get_title(); $link = $product->get_permalink(); $html = '<div class="title-wrapper custom-title"> <p class="name product-title woocommerce-loop-product__title"> <a href="'.$link.'" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">'.$title.'</a> </p> </div>'; } echo $html; } add_action('flatsome_product_box_after','get_sku_category_product'); // Meta description for posts + WooCommerce products function zoyi_meta_description() { if (is_singular()) { global $post; $desc = trim(wp_strip_all_tags(get_the_excerpt($post))); if (empty($desc)) { $desc = trim(wp_strip_all_tags(wp_trim_words($post->post_content, 30, '...'))); } if (!empty($desc)) { echo '<meta name="description" content="' . esc_attr($desc) . '">' . " "; } } } add_action('wp_head', 'zoyi_meta_description', 1); // === SEO: Organization Schema + WebSite Schema + BreadcrumbList Schema === function zoyi_seo_schema() { // Organization Schema $org = array( '@context' => 'https://schema.org', '@type' => 'Organization', 'name' => 'Zoyi Việt Nam', 'url' => 'https://zoyi.vn', 'logo' => 'https://zoyi.vn/wp-content/uploads/2021/08/favicon.png', 'description' => 'Đồng hồ vạn năng và thiết bị đo lường điện chính hãng chất lượng cao', 'address' => array( '@type' => 'PostalAddress', 'addressCountry' => 'VN', ), 'sameAs' => array( 'https://www.facebook.com/zoyi.vietnam', ), ); // WebSite Schema with SearchAction $website = array( '@context' => 'https://schema.org', '@type' => 'WebSite', 'name' => 'Zoyi Việt Nam', 'url' => 'https://zoyi.vn', 'potentialAction' => array( '@type' => 'SearchAction', 'target' => 'https://zoyi.vn/?s={search_term_string}', 'query-input' => 'required name=search_term_string', ), ); echo '<script type="application/ld+json">' . json_encode($org, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>' . "\n"; echo '<script type="application/ld+json">' . json_encode($website, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>' . "\n"; // BreadcrumbList Schema for single posts/products if (is_singular()) { global $post; $breadcrumb = array( '@context' => 'https://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => array(), ); // Home $breadcrumb['itemListElement'][] = array( '@type' => 'ListItem', 'position' => 1, 'name' => 'Trang chủ', 'item' => 'https://zoyi.vn', ); // Blog or Product category if (is_product()) { $breadcrumb['itemListElement'][] = array( '@type' => 'ListItem', 'position' => 2, 'name' => 'Sản phẩm', 'item' => 'https://zoyi.vn/products/', ); } elseif (is_single()) { $breadcrumb['itemListElement'][] = array( '@type' => 'ListItem', 'position' => 2, 'name' => 'Blog', 'item' => 'https://zoyi.vn/blog/', ); } // Current page $breadcrumb['itemListElement'][] = array( '@type' => 'ListItem', 'position' => count($breadcrumb['itemListElement']) + 1, 'name' => get_the_title(), 'item' => get_permalink(), ); echo '<script type="application/ld+json">' . json_encode($breadcrumb, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>' . "\n"; } } add_action('wp_head', 'zoyi_seo_schema', 5); // === SEO: Article Schema for blog posts === function zoyi_article_schema() { if (is_single() && !is_product()) { global $post; $schema = array( '@context' => 'https://schema.org', '@type' => 'Article', 'headline' => get_the_title(), 'url' => get_permalink(), 'datePublished' => get_the_date('c'), 'dateModified' => get_the_modified_date('c'), 'author' => array( '@type' => 'Organization', 'name' => 'Zoyi Việt Nam', 'url' => 'https://zoyi.vn', ), 'publisher' => array( '@type' => 'Organization', 'name' => 'Zoyi Việt Nam', 'logo' => array( '@type' => 'ImageObject', 'url' => 'https://zoyi.vn/wp-content/uploads/2021/08/favicon.png', ), ), 'description' => trim(wp_strip_all_tags(get_the_excerpt($post))), ); if (has_post_thumbnail()) { $schema['image'] = array( '@type' => 'ImageObject', 'url' => get_the_post_thumbnail_url($post, 'full'), ); } echo '<script type="application/ld+json">' . json_encode($schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>' . "\n"; } } add_action('wp_head', 'zoyi_article_schema', 6); // === 8. Open Graph Tags === function zoyi_og_tags() { if (is_front_page() || is_home()) { echo '<meta property="og:type" content="website">' . "\n"; echo '<meta property="og:title" content="Zoyi Vietnam - Dong Ho Van Nang Chinh Hang">' . "\n"; echo '<meta property="og:description" content="Zoyi.vn - Dong ho van nang va thiet bi do luong dien chinh hang chat luong cao.">' . "\n"; echo '<meta property="og:url" content="https://zoyi.vn/">' . "\n"; echo '<meta property="og:image" content="https://zoyi.vn/wp-content/uploads/2021/08/favicon.png">' . "\n"; echo '<meta property="og:site_name" content="Zoyi Vietnam">' . "\n"; } elseif (is_singular()) { global $post; $title = get_the_title(); $desc = trim(wp_strip_all_tags(get_the_excerpt($post))); if (empty($desc)) { $desc = trim(wp_strip_all_tags(wp_trim_words($post->post_content, 30, '...'))); } $url = get_permalink(); $image = has_post_thumbnail() ? get_the_post_thumbnail_url($post, 'large') : 'https://zoyi.vn/wp-content/uploads/2021/08/favicon.png'; echo '<meta property="og:type" content="' . (is_product() ? 'product' : 'article') . '">' . "\n"; echo '<meta property="og:title" content="' . esc_attr($title) . '">' . "\n"; echo '<meta property="og:description" content="' . esc_attr($desc) . '">' . "\n"; echo '<meta property="og:url" content="' . esc_url($url) . '">' . "\n"; echo '<meta property="og:image" content="' . esc_url($image) . '">' . "\n"; echo '<meta property="og:site_name" content="Zoyi Vietnam">' . "\n"; echo '<meta name="twitter:card" content="summary_large_image">' . "\n"; echo '<meta name="twitter:title" content="' . esc_attr($title) . '">' . "\n"; echo '<meta name="twitter:description" content="' . esc_attr($desc) . '">' . "\n"; } elseif (is_archive() || is_category()) { $title = get_the_archive_title(); echo '<meta property="og:type" content="website">' . "\n"; echo '<meta property="og:title" content="' . esc_attr($title) . ' | Zoyi Vietnam">' . "\n"; echo '<meta property="og:url" content="' . esc_url(get_permalink()) . '">' . "\n"; echo '<meta property="og:site_name" content="Zoyi Vietnam">' . "\n"; } } add_action('wp_head', 'zoyi_og_tags', 2); // === 9. Title Fix for Flatsome === function zoyi_fix_title($title_parts) { if (is_front_page() || is_home()) { $title_parts['title'] = 'Dong ho van nang chinh hang - Zoyi Vietnam'; } elseif (is_single()) { $title_parts['title'] = get_the_title() . ' | Zoyi Vietnam'; } elseif (is_page()) { $title_parts['title'] = get_the_title() . ' | Zoyi Vietnam'; } unset($title_parts['site']); return $title_parts; } add_filter('document_title_parts', 'zoyi_fix_title', 20); // === 9b. Category Pages SEO === // Meta description for categories/tags without custom description add_action('wp_head', function() { if (!is_category() && !is_tag() && !is_tax()) return; $obj = get_queried_object(); if (!$obj) return; $desc = $obj->description; if (!$desc) { $name = $obj->name; if (is_category()) { $desc = 'Tim hieu ve ' . $name . ' - Xem review, huong dan su dung, so sanh gia ' . $name . ' chinh hang tai Zoyi Vietnam. San pham chat luong cao, gia tot.'; } elseif (is_tag()) { $desc = 'Cac bai viet ve ' . $name . ' - Huong dan, review chi tiet tai Zoyi Vietnam.'; } } if ($desc) { echo '<meta name="description" content="' . esc_attr($desc) . '">' . "\\n"; } }, 1); // Category BreadcrumbList Schema add_action('wp_head', function() { if (!is_category() && !is_tag() && !is_tax()) return; $obj = get_queried_object(); if (!$obj) return; $name = $obj->name; $url = get_term_link($obj); if (is_wp_error($url)) return; $schema = array( '@context' => 'https://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => array( array('@type' => 'ListItem', 'position' => 1, 'name' => 'Trang chu', 'item' => 'https://zoyi.vn/'), array('@type' => 'ListItem', 'position' => 2, 'name' => $name, 'item' => $url) ) ); echo '<script type="application/ld+json">' . json_encode($schema, JSON_UNESCAPED_UNICODE) . '</script>' . "\\n"; }, 1); // === 9c. LocalBusiness / Store Schema (GEO Optimization) === // Add Store schema ONLY on homepage add_action('wp_head', function() { if (!is_front_page() && !is_home()) return; $schema = array( '@context' => 'https://schema.org', '@type' => array('Store', 'LocalBusiness', 'Organization'), 'name' => 'Zoyi Vietnam - Dong Ho Van Nang Chinh Hang', 'description' => 'Zoyi Vietnam phan phoi dong ho van nang, thiet bi do luong dien chinh hang. San pham ZOYI chat luong cao, gia tot, bao hanh 12 thang.', 'url' => 'https://zoyi.vn/', 'telephone' => '+84-28-XXXX-XXXX', 'email' => 'contact@zoyi.vn', 'address' => array( '@type' => 'PostalAddress', 'streetAddress' => 'XX Le Lai, Q1', 'addressLocality' => 'Ho Chi Minh City', 'addressRegion' => 'Ho Chi Minh', 'postalCode' => '700000', 'addressCountry' => 'VN' ), 'geo' => array( '@type' => 'GeoCoordinates', 'latitude' => '10.7769', 'longitude' => '106.7009' ), 'openingHoursSpecification' => array( array('@type' => 'OpeningHoursSpecification', 'dayOfWeek' => array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'), 'opens' => '08:00', 'closes' => '18:00') ), 'sameAs' => array('https://www.facebook.com/zoyivietnam'), 'priceRange' => '₫₫', 'image' => 'https://zoyi.vn/wp-content/uploads/2021/08/favicon.png' ); echo '<script type="application/ld+json">' . json_encode($schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>' . "\\n"; }, 3); // FAQ Schema for blog posts (AIO optimization - helps appear in AI Overviews) add_action('wp_head', function() { if (!is_single()) return; global $post; if (!$post) return; // Only add FAQ schema if post has FAQ content in first few paragraphs $content = $post->post_content; // Check if content has at least one question format if (!preg_match('/(câu hỏi|tại sao|bao nhieu|bao lâu|lam sao|hướng dẫn|là gì|là bao nhiêu|nên|mấy)/i', $content)) return; $faqs = array(); // Extract Q&A pairs from content preg_match_all('/<h([23])[^>]*>([^<]*)<\/h[23]>/i', $content, $matches); for ($i = 0; $i < count($matches[0]) - 1; $i++) { $q = trim(strip_tags($matches[2][$i])); $next_idx = $i + 1; $a_start = strpos($content, $matches[0][$i]) + strlen($matches[0][$i]); $a_end = isset($matches[0][$next_idx]) ? strpos($content, $matches[0][$next_idx]) : strlen($content); $a_text = trim(strip_tags(substr($content, $a_start, $a_end - $a_start))); if (strlen($q) > 5 && strlen($a_text) > 10 && strlen($a_text) < 500) { $faqs[] = array('@type' => 'Question', 'name' => $q, 'acceptedAnswer' => array('@type' => 'Answer', 'text' => $a_text)); } if (count($faqs) >= 5) break; } if (empty($faqs)) return; $schema = array('@context' => 'https://schema.org', '@type' => 'FAQPage', 'mainEntity' => $faqs); echo '<script type="application/ld+json">' . json_encode($schema, JSON_UNESCAPED_UNICODE) . '</script>' . "\\n"; }, 1); // === 10. WooCommerce Product Schema// === 10. WooCommerce Product Schema (Enhanced) === add_action('wp', function() { $type = get_post_type(get_queried_object_id()); if ($type !== 'product') return; if (!function_exists('wc_get_product')) return; $pid = get_queried_object_id(); $product = wc_get_product($pid); if (!$product) return; $name = get_the_title(); $desc = wp_strip_all_tags($product->get_description()); if (strlen($desc) > 500) $desc = mb_substr($desc, 0, 500); $url = get_permalink(); $img = wp_get_attachment_url($product->get_image_id()); $price = $product->get_price(); $reg_price = $product->get_regular_price(); $sale_price = $product->get_sale_price(); $curr = get_woocommerce_currency(); $avail = $product->is_in_stock() ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock'; $sku = $product->get_sku() ?: 'ZOYI-' . $pid; $rc = $product->get_rating_count(); $ar = $product->get_average_rating(); $schema = array( '@context' => 'https://schema.org', '@type' => 'Product', 'name' => $name, 'description' => $desc, 'url' => $url, 'image' => $img, 'brand' => array('@type' => 'Brand', 'name' => 'ZOYI'), 'sku' => $sku, 'offers' => array( '@type' => 'Offer', 'price' => $price ?: '0', 'priceCurrency' => $curr, 'availability' => $avail, 'seller' => array('@type' => 'Organization', 'name' => 'Zoyi Vietnam'), 'url' => $url, 'shippingDetails' => array( '@type' => 'OfferShippingDetails', 'shippingRate' => array('@type' => 'MonetaryAmount', 'value' => '0', 'currency' => 'VND'), 'deliveryTime' => array('@type' => 'ShippingDeliveryTime', 'handlingTime' => array('@type' => 'QuantitativeValue', 'minValue' => '0', 'maxValue' => '1', 'unitCode' => 'DAY'), 'transitTime' => array('@type' => 'QuantitativeValue', 'minValue' => '1', 'maxValue' => '3', 'unitCode' => 'DAY')) ), 'hasMerchantReturnPolicy' => array('@type' => 'MerchantReturnPolicy', 'returnPolicyCategory' => 'https://schema.org/MerchantReturnFiniteReturnWindow', 'merchantReturnDays' => '7') ) ); if ($sale_price && floatval($sale_price) > 0) { $schema['offers']['priceSpecification'] = array('@type' => 'UnitPriceSpecification', 'price' => $reg_price, 'priceCurrency' => $curr, 'unitCode' => 'UNIT'); } if ($rc > 0) { $schema['aggregateRating'] = array('@type' => 'AggregateRating', 'ratingValue' => number_format($ar, 1), 'reviewCount' => $rc, 'bestRating' => '5', 'worstRating' => '1'); } echo '<script type="application/ld+json">' . json_encode($schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>' . "\\n"; }, 5); // === 10. WooCommerce Product Schema === add_action('wp', function() { $type = get_post_type(get_queried_object_id()); if ($type !== 'product') return; if (!function_exists('wc_get_product')) return; $pid = get_queried_object_id(); $product = wc_get_product($pid); if (!$product) return; $name = get_the_title(); $desc = wp_strip_all_tags($product->get_description()); if (strlen($desc) > 500) $desc = mb_substr($desc, 0, 500); $url = get_permalink(); $img = wp_get_attachment_url($product->get_image_id()); $price = $product->get_price(); $curr = get_woocommerce_currency(); $avail = $product->is_in_stock() ? 'InStock' : 'OutOfStock'; $sku = $product->get_sku() ?: 'ZOYI-' . $pid; $rc = $product->get_rating_count(); $ar = $product->get_average_rating(); $schema = array( '@context' => 'https://schema.org', '@type' => 'Product', 'name' => $name, 'description' => $desc, 'url' => $url, 'image' => $img, 'brand' => array('@type' => 'Brand', 'name' => 'ZOYI'), 'offers' => array('@type' => 'Offer', 'price' => $price, 'priceCurrency' => $curr, 'availability' => 'https://schema.org/' . $avail, 'seller' => array('@type' => 'Organization', 'name' => 'Zoyi Vietnam')), 'sku' => $sku ); if ($rc > 0) $schema['aggregateRating'] = array('@type' => 'AggregateRating', 'ratingValue' => number_format($ar, 1), 'reviewCount' => $rc); echo '<script type="application/ld+json">' . json_encode($schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>' . "\\n"; }, 5); // === 11. Lazy Loading for Images === function zoyi_lazy_load_images($content) { if (is_feed() || is_preview() || is_admin()) return $content; return str_replace(' src="https://zoyi.vn/wp-content/uploads/', ' loading="lazy" src="https://zoyi.vn/wp-content/uploads/', $content); } add_filter('the_content', 'zoyi_lazy_load_images', 99);