// Add custom Theme Functions here // function devvn_remove_slug( $post_link, $post ) { if ( !in_array( get_post_type($post), array( 'product' ) ) || 'publish' != $post->post_status ) { return $post_link; } if('product' == $post->post_type){ $post_link = str_replace( '/san-pham/', '/', $post_link ); //Thay cua-hang bằng slug hiện tại của bạn }else{ $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); } return $post_link; } add_filter( 'post_type_link', 'devvn_remove_slug', 10, 2 ); /*Sửa lỗi 404 sau khi đã remove slug product hoặc cua-hang*/ function devvn_woo_product_rewrite_rules($flash = false) { global $wp_post_types, $wpdb; $siteLink = esc_url(home_url('/')); foreach ($wp_post_types as $type=>$custom_post) { if($type == 'product'){ if ($custom_post->_builtin == false) { $querystr = "SELECT {$wpdb->posts}.post_name, {$wpdb->posts}.ID FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_status = 'publish' AND {$wpdb->posts}.post_type = '{$type}'"; $posts = $wpdb->get_results($querystr, OBJECT); foreach ($posts as $post) { $current_slug = get_permalink($post->ID); $base_product = str_replace($siteLink,'',$current_slug); add_rewrite_rule($base_product.'?$', "index.php?{$custom_post->query_var}={$post->post_name}", 'top'); add_rewrite_rule($base_product.'comment-page-([0-9]{1,})/?$', 'index.php?'.$custom_post->query_var.'='.$post->post_name.'&cpage=$matches[1]', 'top'); add_rewrite_rule($base_product.'(?:feed/)?(feed|rdf|rss|rss2|atom)/?$', 'index.php?'.$custom_post->query_var.'='.$post->post_name.'&feed=$matches[1]','top'); } } } } if ($flash == true) flush_rewrite_rules(false); } add_action('init', 'devvn_woo_product_rewrite_rules'); /*Fix lỗi khi tạo sản phẩm mới bị 404*/ function devvn_woo_new_product_post_save($post_id){ global $wp_post_types; $post_type = get_post_type($post_id); foreach ($wp_post_types as $type=>$custom_post) { if ($custom_post->_builtin == false && $type == $post_type) { devvn_woo_product_rewrite_rules(true); } } } add_action('wp_insert_post', 'devvn_woo_new_product_post_save'); function devvn_custom_woocommerce_structured_data_product ($data) { global $product; $data['brand'] = $product->get_attribute('pa_sachifoods') ? $product->get_attribute('pa_sachifoods') : null; $data['mpn'] = $product->get_sku() ? $product->get_sku() : null; $data['id'] = $product->get_id() ? $product->get_id() : null; return $data; } add_filter( 'woocommerce_structured_data_product', 'devvn_custom_woocommerce_structured_data_product' ); /* * Remove product-category in URL * Thay product-category bằng slug hiện tại của bạn. Mặc định là product-category */ add_filter( 'term_link', 'devvn_product_cat_permalink', 10, 3 ); function devvn_product_cat_permalink( $url, $term, $taxonomy ){ switch ($taxonomy): case 'product_cat': $taxonomy_slug = 'danh-muc'; //Thay bằng slug hiện tại của bạn. Mặc định là product-category if(strpos($url, $taxonomy_slug) === FALSE) break; $url = str_replace('/' . $taxonomy_slug, '', $url); break; endswitch; return $url; } // Add our custom product cat rewrite rules function devvn_product_category_rewrite_rules($flash = false) { $terms = get_terms( array( 'taxonomy' => 'product_cat', 'post_type' => 'product', 'hide_empty' => false, )); if($terms && !is_wp_error($terms)){ $siteurl = esc_url(home_url('/')); foreach ($terms as $term){ $term_slug = $term->slug; $baseterm = str_replace($siteurl,'',get_term_link($term->term_id,'product_cat')); add_rewrite_rule($baseterm.'?$','index.php?product_cat='.$term_slug,'top'); add_rewrite_rule($baseterm.'page/([0-9]{1,})/?$', 'index.php?product_cat='.$term_slug.'&paged=$matches[1]','top'); add_rewrite_rule($baseterm.'(?:feed/)?(feed|rdf|rss|rss2|atom)/?$', 'index.php?product_cat='.$term_slug.'&feed=$matches[1]','top'); } } if ($flash == true) flush_rewrite_rules(false); } add_action('init', 'devvn_product_category_rewrite_rules'); /*Sửa lỗi khi tạo mới taxomony bị 404*/ add_action( 'create_term', 'devvn_new_product_cat_edit_success', 10, 2 ); function devvn_new_product_cat_edit_success( $term_id, $taxonomy ) { devvn_product_category_rewrite_rules(true); } add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' ); // < 2.1 add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 + function woo_custom_cart_button_text() { return __( 'Xem chi tiết', 'woocommerce' ); }{"id":1234,"count":1,"description":"","link":"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/","name":"5 c\u00e1ch x\u00e0o nh\u1ed9ng ngon b\u00e9o","slug":"5-cach-xao-nhong-ngon-beo","taxonomy":"post_tag","meta":[],"yoast_head":"\nL\u01b0u tr\u1eef 5 c\u00e1ch x\u00e0o nh\u1ed9ng ngon b\u00e9o - Sachi Foods - B\u00e1nh Tr\u00e1ng Sachi<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"L\u01b0u tr\u1eef 5 c\u00e1ch x\u00e0o nh\u1ed9ng ngon b\u00e9o - Sachi Foods - B\u00e1nh Tr\u00e1ng Sachi\" \/>\n<meta property=\"og:url\" content=\"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/\" \/>\n<meta property=\"og:site_name\" content=\"Sachi Foods - B\u00e1nh Tr\u00e1ng Sachi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"CollectionPage\",\"@id\":\"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/\",\"url\":\"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/\",\"name\":\"L\u01b0u tr\u1eef 5 c\u00e1ch x\u00e0o nh\u1ed9ng ngon b\u00e9o - Sachi Foods - B\u00e1nh Tr\u00e1ng Sachi\",\"isPartOf\":{\"@id\":\"https:\/\/banhtrangsachi.com\/#website\"},\"breadcrumb\":{\"@id\":\"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/#breadcrumb\"},\"inLanguage\":\"vi\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Trang ch\u1ee7\",\"item\":\"https:\/\/banhtrangsachi.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"5 c\u00e1ch x\u00e0o nh\u1ed9ng ngon b\u00e9o\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/banhtrangsachi.com\/#website\",\"url\":\"https:\/\/banhtrangsachi.com\/\",\"name\":\"Sachi Foods - B\u00e1nh Tr\u00e1ng Sachi\",\"description\":\"B\u00e1nh Tr\u00e1ng, B\u00e1nh \u0110a, B\u00e1nh N\u01b0\u1edbng\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/banhtrangsachi.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"vi\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"L\u01b0u tr\u1eef 5 c\u00e1ch x\u00e0o nh\u1ed9ng ngon b\u00e9o - Sachi Foods - B\u00e1nh Tr\u00e1ng Sachi","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/","og_locale":"vi_VN","og_type":"article","og_title":"L\u01b0u tr\u1eef 5 c\u00e1ch x\u00e0o nh\u1ed9ng ngon b\u00e9o - Sachi Foods - B\u00e1nh Tr\u00e1ng Sachi","og_url":"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/","og_site_name":"Sachi Foods - B\u00e1nh Tr\u00e1ng Sachi","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"CollectionPage","@id":"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/","url":"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/","name":"L\u01b0u tr\u1eef 5 c\u00e1ch x\u00e0o nh\u1ed9ng ngon b\u00e9o - Sachi Foods - B\u00e1nh Tr\u00e1ng Sachi","isPartOf":{"@id":"https:\/\/banhtrangsachi.com\/#website"},"breadcrumb":{"@id":"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/#breadcrumb"},"inLanguage":"vi"},{"@type":"BreadcrumbList","@id":"https:\/\/banhtrangsachi.com\/tag\/5-cach-xao-nhong-ngon-beo\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Trang ch\u1ee7","item":"https:\/\/banhtrangsachi.com\/"},{"@type":"ListItem","position":2,"name":"5 c\u00e1ch x\u00e0o nh\u1ed9ng ngon b\u00e9o"}]},{"@type":"WebSite","@id":"https:\/\/banhtrangsachi.com\/#website","url":"https:\/\/banhtrangsachi.com\/","name":"Sachi Foods - B\u00e1nh Tr\u00e1ng Sachi","description":"B\u00e1nh Tr\u00e1ng, B\u00e1nh \u0110a, B\u00e1nh N\u01b0\u1edbng","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/banhtrangsachi.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"}]}},"_links":{"self":[{"href":"https:\/\/banhtrangsachi.com\/wp-json\/wp\/v2\/tags\/1234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/banhtrangsachi.com\/wp-json\/wp\/v2\/tags"}],"about":[{"href":"https:\/\/banhtrangsachi.com\/wp-json\/wp\/v2\/taxonomies\/post_tag"}],"wp:post_type":[{"href":"https:\/\/banhtrangsachi.com\/wp-json\/wp\/v2\/posts?tags=1234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}