<?php // Add custom Theme Functions here // ======================= // 1. Di chuyển archive description WooCommerce // ======================= add_action('woocommerce_archive_description', 'custom_archive_description', 2 ); function custom_archive_description(){ if( is_product_category() ) : remove_action('woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 ); add_action( 'woocommerce_after_main_content', 'woocommerce_taxonomy_archive_description', 5 ); endif; } // ======================= // 3. Đổi slug post type featured_item // ======================= function change_slug_of_post_type_portfolio() { $args = get_post_type_object("featured_item"); if ( $args && isset( $args->rewrite ) && is_array( $args->rewrite ) ) { $args->rewrite["slug"] = "phao-khung-tranh"; register_post_type($args->name, (array) $args); } } add_action('init', 'change_slug_of_post_type_portfolio', 20); // ======================= // 4. Tối giản field checkout WooCommerce // ======================= add_filter( 'woocommerce_checkout_fields' , 'custom_fields_woocommerce' ); function custom_fields_woocommerce( $fields ) { unset( $fields['billing']['billing_last_name'] ); unset( $fields['billing']['billing_country'] ); unset( $fields['billing']['billing_postcode'] ); unset( $fields['billing']['billing_city'] ); unset( $fields['billing']['billing_company'] ); unset( $fields['billing']['billing_email'] ); return $fields; } // ======================= // 6. Vô hiệu hoá WooCommerce blocks (JS/CSS) trên frontend // ======================= function disable_woocommerce_blocks() { wp_dequeue_style('wc-blocks-style'); wp_deregister_style('wc-blocks-style'); wp_dequeue_script('wc-blocks'); wp_deregister_script('wc-blocks'); } add_action('wp_enqueue_scripts', 'disable_woocommerce_blocks', 99); // ======================= // 7. Vô hiệu hoá script Stripe ngoài trang thanh toán/giỏ hàng // ======================= function disable_stripe_scripts() { if ( ! is_checkout() && ! is_cart() ) { wp_dequeue_script('stripe'); wp_deregister_script('stripe'); wp_dequeue_script('woocommerce_stripe'); wp_deregister_script('woocommerce_stripe'); } } add_action('wp_enqueue_scripts', 'disable_stripe_scripts', 99); // ======================= // 8. Bỏ DNS prefetch s.w.org // ======================= function remove_dns_prefetch_s_w_org($hints, $relation_type) { if ('dns-prefetch' === $relation_type) { $key = array_search('https://s.w.org', $hints, true); if (false !== $key) { unset($hints[$key]); } } return $hints; } add_filter('wp_resource_hints', 'remove_dns_prefetch_s_w_org', 10, 2); // ======================= // 9. Bỏ jquery-migrate trên frontend // ======================= function remove_jquery_migrate( $scripts ) { if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) { $script = $scripts->registered['jquery']; if ( $script->deps ) { $script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) ); } } } add_action( 'wp_default_scripts', 'remove_jquery_migrate' ); // ======================= // 10. Loại bớt meta/head, RSS, emoji, embed... // ======================= // Remove WordPress meta generator tag remove_action('wp_head', 'wp_generator'); // Remove WooCommerce meta generator tag add_action('wp_loaded', 'remove_woocommerce_generator_tag'); function remove_woocommerce_generator_tag() { if ( isset( $GLOBALS['woocommerce'] ) ) { remove_action('wp_head', array($GLOBALS['woocommerce'], 'generator')); } } remove_action('wp_head', 'wc_generator_tag'); // Remove emoji styles and scripts remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action('admin_print_scripts', 'print_emoji_detection_script'); remove_action('admin_print_styles', 'print_emoji_styles'); // Filter to remove TinyMCE emojis add_filter('tiny_mce_plugins', 'disable_emojis_tinymce'); function disable_emojis_tinymce($plugins) { if (is_array($plugins)) { return array_diff($plugins, array('wpemoji')); } return array(); } // Prevent DNS prefetching for emojis add_filter('emoji_svg_url', '__return_false'); // Disable wp-embed script function disable_wp_embed() { wp_deregister_script('wp-embed'); } add_action('wp_footer', 'disable_wp_embed'); // Remove RSS feed links from head remove_action('wp_head', 'feed_links', 2); remove_action('wp_head', 'feed_links_extra', 3); // Disable all RSS/Atom feeds function disable_feeds() { wp_die(__('No feed available. Please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!')); } add_action('do_feed', 'disable_feeds', 1); add_action('do_feed_rdf', 'disable_feeds', 1); add_action('do_feed_rss', 'disable_feeds', 1); add_action('do_feed_rss2', 'disable_feeds', 1); add_action('do_feed_atom', 'disable_feeds', 1); add_action('do_feed_rss2_comments', 'disable_feeds', 1); add_action('do_feed_atom_comments', 'disable_feeds', 1); // Remove generator tag from RSS feeds function remove_rss_generator() { return ''; } add_filter('the_generator', 'remove_rss_generator'); // Remove Windows Live Writer manifest link remove_action('wp_head', 'wlwmanifest_link'); // Remove RSD link remove_action('wp_head', 'rsd_link'); // Remove shortlink from HTTP headers remove_action('template_redirect', 'wp_shortlink_header', 11); // ======================= // 11. (Rất rủi ro) Tắt kiểm tra update plugin - bạn đang dùng // ======================= remove_action('load-plugins.php', 'wp_update_plugins'); remove_action('load-update.php', 'wp_update_plugins'); remove_action('admin_init', '_maybe_update_plugins'); remove_action('wp_update_plugins', 'wp_update_plugins'); remove_action('do_all_pings', 'wp_update_plugins'); remove_action('wp_version_check', 'wp_update_plugins'); remove_action('admin_init', '_maybe_update_plugins'); add_filter('pre_site_transient_update_plugins', '__return_null'); // ======================= // 12. Bỏ một số script không cần thiết // ======================= function remove_unnecessary_scripts() { if (!is_admin()) { wp_deregister_script('jquery-migrate'); } if (!current_user_can('manage_options')) { wp_dequeue_script('query-monitor'); } if (!is_user_logged_in()) { wp_dequeue_script('admin-bar'); } wp_dequeue_script('hoverIntent'); } add_action('wp_enqueue_scripts', 'remove_unnecessary_scripts', 100); // Thumbnail gallery nhỏ hơn add_filter( 'woocommerce_get_image_size_gallery_thumbnail', function( $size ) { return array( 'width' => 125, 'height' => 125, 'crop' => 1, ); } ); // ======================= // 13. LOG PERF TRANG PRODUCT (WCVD PERF TEST) // ======================= // Bật lưu query nếu chưa bật (có thể đã khai báo trong wp-config.php) if ( ! defined( 'SAVEQUERIES' ) ) { define( 'SAVEQUERIES', true ); } /** * Log thời gian PHP xử lý + số lượng query SQL trên TRANG SẢN PHẨM. */ add_action( 'shutdown', function() { if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) { return; } if ( ! function_exists( 'is_product' ) || ! is_product() ) { return; } $time = timer_stop( 0, 3 ); global $wpdb; $queries = ( isset( $wpdb->queries ) && is_array( $wpdb->queries ) ) ? count( $wpdb->queries ) : 0; error_log( sprintf( 'WCVD PERF TEST: PAGE TIME (PHP) on single product: %s s, SQL QUERIES: %d', $time, $queries ) ); } ); // ======================= // 13. TAT JS MINI CART // ======================= add_action('wp_enqueue_scripts', 'wptangtoc_clear_ajax_dieu_kien_gio_hang', 99); function wptangtoc_clear_ajax_dieu_kien_gio_hang() { if(function_exists('is_woocommerce')) { wp_dequeue_script('wc-cart-fragments'); wp_deregister_script('wc-cart-fragments'); } } // ======================= // 14. THEM SCHEMA // ======================= add_filter('rank_math/json_ld', function ($data, $jsonld) { // Chỉ áp dụng cho TRANG CHỦ (front page). Nếu homepage là posts page thì thêm is_home() bên dưới. if ( ! is_front_page() ) { return $data; } // ========= 1) INPUT (từ bạn cung cấp) ========= $site_url = 'https://khungtranhre.com/'; $brand = 'KHUNG TRANH RẺ'; $logo_url = 'https://khungtranhre.com/wp-content/uploads/2026/01/logo-vuong.png'; $images = [ 'https://khungtranhre.com/wp-content/uploads/2022/05/banner-ngang-khung-tranh-re.jpg', 'https://khungtranhre.com/wp-content/uploads/2022/05/banner-khungtranhre.jpg', $logo_url, ]; // Địa chỉ: để “khớp Google Maps listing” + vẫn đúng mô tả mới // StreetAddress + Locality tách rõ ràng giúp Google hiểu tốt hơn. $address = [ '@type' => 'PostalAddress', 'streetAddress' => '38, Athena Complex, Xuân Phương', 'addressLocality' => 'Nam Từ Liêm', 'addressRegion' => 'Hà Nội', 'addressCountry' => 'VN', ]; // Tọa độ lấy trực tiếp từ link maps bạn gửi (dạng number) $geo = [ '@type' => 'GeoCoordinates', 'latitude' => 21.0400562, 'longitude' => 105.7343999, ]; $map_url = 'https://maps.app.goo.gl/g3QYHUz2Gk6poqE9A'; $phone_e164 = '+84988391380'; $email = 'xuongkhungtranhre@gmail.com'; // Giờ mở cửa: 8h–17h hằng ngày $opening_hours = [[ '@type' => 'OpeningHoursSpecification', 'dayOfWeek' => ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'], 'opens' => '08:00', 'closes' => '17:00', ]]; $same_as = [ 'https://www.facebook.com/khungtranhre', 'https://twitter.com/khungtranhre', ]; $legal_pages = [ 'about' => 'https://khungtranhre.com/gioi-thieu/', 'contact' => 'https://khungtranhre.com/lien-he/', 'privacy' => 'https://khungtranhre.com/chinh-sach-bao-mat/', 'terms' => 'https://khungtranhre.com/chinh-sach-ban-hang/', ]; $price_range = '10000-1000000 VND'; // ========= 2) IDs thống nhất ========= $org_id = rtrim($site_url, '/') . '/#organization'; $website_id = rtrim($site_url, '/') . '/#website'; $webpage_id = rtrim($site_url, '/') . '/#webpage'; $logo_id = rtrim($site_url, '/') . '/#logo'; $biz_id = rtrim($site_url, '/') . '/#localbusiness'; // ========= 3) Helper: tìm node Organization của Rank Math để "làm dày" ========= $org_key = null; foreach ($data as $key => $node) { if (!is_array($node) || empty($node['@type']) || empty($node['@id'])) continue; $types = is_array($node['@type']) ? $node['@type'] : [$node['@type']]; if (in_array('Organization', $types, true) && $node['@id'] === $org_id) { $org_key = $key; break; } } // Nếu Rank Math chưa tạo đúng key Organization (hiếm), ta tự tạo if ($org_key === null) { $data['Organization'] = [ '@type' => 'Organization', '@id' => $org_id, 'name' => $brand, ]; $org_key = 'Organization'; } // ========= 4) Làm dày Organization ========= $data[$org_key]['name'] = $brand; $data[$org_key]['url'] = $site_url; $data[$org_key]['logo'] = [ '@type' => 'ImageObject', '@id' => $logo_id, 'url' => $logo_url, ]; $data[$org_key]['image'] = $images; $data[$org_key]['sameAs'] = $same_as; $data[$org_key]['email'] = $email; // ContactPoint cho Organization (tốt cho Knowledge Graph) $data[$org_key]['contactPoint'] = [[ '@type' => 'ContactPoint', 'telephone' => $phone_e164, 'email' => $email, 'contactType' => 'customer support', 'areaServed' => 'VN', 'availableLanguage' => ['vi'], ]]; // ========= 5) Ensure WebSite/WebPage trỏ đúng publisher/about ========= foreach ($data as $key => $node) { if (!is_array($node) || empty($node['@type']) || empty($node['@id'])) continue; if ($node['@id'] === $website_id) { // WebSite.publisher -> Organization $data[$key]['publisher'] = ['@id' => $org_id]; $data[$key]['url'] = rtrim($site_url, '/'); // RankMath hay dùng không slash $data[$key]['name'] = $brand; } if ($node['@id'] === $webpage_id) { // WebPage.about -> Organization, isPartOf -> WebSite $data[$key]['about'] = ['@id' => $org_id]; $data[$key]['isPartOf'] = ['@id' => $website_id]; $data[$key]['url'] = $site_url; } } // ========= 6) Add Logo ImageObject node (để graph rõ ràng hơn) ========= $data['Logo'] = [ '@type' => 'ImageObject', '@id' => $logo_id, 'url' => $logo_url, ]; // ========= 7) Add/replace LocalBusiness node (FurnitureStore) ========= $data['LocalBusiness'] = [ '@type' => ['LocalBusiness', 'FurnitureStore'], '@id' => $biz_id, 'name' => $brand, 'url' => $site_url, 'image' => $images, 'logo' => ['@id' => $logo_id], 'telephone' => $phone_e164, 'email' => $email, 'parentOrganization' => ['@id' => $org_id], 'address' => $address, 'geo' => $geo, 'hasMap' => $map_url, 'openingHoursSpecification' => $opening_hours, 'areaServed' => [ '@type' => 'Country', 'name' => 'Vietnam', ], 'contactPoint' => [[ '@type' => 'ContactPoint', 'telephone' => $phone_e164, 'email' => $email, 'contactType' => 'customer support', 'areaServed' => 'VN', 'availableLanguage' => ['vi'], ]], 'sameAs' => $same_as, 'priceRange' => $price_range, 'currenciesAccepted' => 'VND', // Trang pháp lý (không bắt buộc nhưng sạch + hữu ích) 'subjectOf' => [ ['@type' => 'WebPage', 'url' => $legal_pages['about'], 'name' => 'Giới thiệu'], ['@type' => 'WebPage', 'url' => $legal_pages['contact'], 'name' => 'Liên hệ'], ['@type' => 'WebPage', 'url' => $legal_pages['privacy'], 'name' => 'Chính sách bảo mật'], ['@type' => 'WebPage', 'url' => $legal_pages['terms'], 'name' => 'Chính sách bán hàng'], ], ]; return $data; }, 99, 2); // ======================= // 14. 301 phan trang 404 // ======================= add_action('template_redirect', 'redirect_custom_404_pagination'); function redirect_custom_404_pagination() { // Chỉ chạy nếu là trang lỗi 404 if ( is_404() ) { $url = $_SERVER['REQUEST_URI']; // Kiểm tra xem trong URL có chứa chuỗi "/page/số_thứ_tự/" hay không if ( preg_match('#/page/[0-9]+/?#', $url) ) { // Xóa phần "/page/xxx/" khỏi URL để lấy link gốc $redirect_url = preg_replace('#/page/[0-9]+/?.*#', '', $url); // Chuyển hướng 301 về link gốc đó wp_redirect( home_url( $redirect_url ), 301 ); exit(); } } } https://khungtranhre.com/post-sitemap.xml 2026-01-29T09:52:35+00:00 https://khungtranhre.com/page-sitemap.xml 2026-03-24T08:18:34+00:00 https://khungtranhre.com/product-sitemap.xml 2026-04-29T04:20:58+00:00 https://khungtranhre.com/featured_item-sitemap.xml 2022-05-11T03:45:46+00:00 https://khungtranhre.com/product_cat-sitemap.xml 2026-04-29T04:20:58+00:00