<?php
add_action("wp_enqueue_scripts","kadence_child_enqueue_styles",20);function kadence_child_enqueue_styles(){wp_enqueue_style("kadence-parent-style",get_template_directory_uri()."/style.css");wp_enqueue_style("kadence-child-style",get_stylesheet_uri(),array("kadence-parent-style"),"1.0.0");}
add_action("wp_head","mirametal_fix",999);function mirametal_fix(){?><style>html,body{background:#fff!important}.woocommerce-shop .site-container,.tax-product_cat .site-container,.archive.woocommerce .site-container,.woocommerce-page .site-container,.woocommerce .site-container,#page .site-container,.site-container,.content-container,.container{width:100%!important;max-width:100%!important;padding-left:20px!important;padding-right:20px!important;box-sizing:border-box!important}#primary.content-area,.woocommerce #primary,.archive #primary{width:100%!important;max-width:100%!important;flex:0 0 100%!important}#secondary,.sidebar,.widget-area{display:none!important}.woocommerce ul.products,.woocommerce-page ul.products,ul.products{width:100%!important;display:grid!important;grid-template-columns:repeat(auto-fill,minmax(260px,1fr))!important;gap:20px!important;list-style:none!important;padding:0!important}ul.products li.product{width:100%!important;padding:10px!important;float:none!important}ul.products li.product img{width:100%!important;aspect-ratio:1/1!important;object-fit:cover!important}ul.products li.product .woocommerce-loop-product__title{font-size:15px!important;display:-webkit-box!important;-webkit-line-clamp:2!important;-webkit-box-orient:vertical!important;overflow:hidden!important}ul.products li.product .price{font-size:16px!important;font-weight:600!important}ul.products li.product .button{width:100%!important;text-align:center!important}@media only screen and (max-width:767px){.woocommerce ul.products,.woocommerce-page ul.products,ul.products{grid-template-columns:repeat(2,1fr)!important;gap:10px!important;padding-left:6px!important;padding-right:6px!important}ul.products li.product{padding:6px!important}.site-container,.content-container,.container{padding-left:8px!important;padding-right:8px!important}}</style><?php }
/**
* Fix: 阻止 Rank Math 输出错误的 canonical
* 让当前带 ?lang= 的 URL 成为唯一 canonical
*/
add_filter('rank_math/frontend/canonical', function($canonical) {
// 返回当前完整 URL(保留 ?lang= 参数)
return home_url(add_query_arg(array()));
}, 999);
/**
* 修复多语言产品页 Canonical 和 Hreflang
*/
add_action('wp_head', 'fix_mira_multilingual_seo', 1);
function fix_mira_multilingual_seo() {
if (!is_singular('product')) {
return;
}
$product_id = get_the_ID();
$base_url = get_permalink($product_id);
$current_lang = isset($_GET['lang']) ? sanitize_text_field($_GET['lang']) : 'en';
$languages = ['en', 'fr', 'it', 'es', 'de', 'pt'];
// 正确的 Canonical(自指)
$canonical = add_query_arg('lang', $current_lang, $base_url);
echo '<link rel="canonical" href="' . esc_url($canonical) . '" />' . "\n";
// 所有语言的 hreflang
foreach ($languages as $lang) {
$lang_url = add_query_arg('lang', $lang, $base_url);
echo '<link rel="alternate" hreflang="' . esc_attr($lang) . '" href="' . esc_url($lang_url) . '" />' . "\n";
}
// x-default
echo '<link rel="alternate" hreflang="x-default" href="' . esc_url($base_url) . '" />' . "\n";
}
/**
* 清理插件生成的错误/重复 SEO 标签
*/
add_action('wp_head', function() {
if (!is_singular('product')) return;
ob_start(function($buffer) {
// 移除不带 ?lang= 参数的 canonical(插件生成的错误版本)
$buffer = preg_replace('/<link rel="canonical" href="https:\/\/mirametaljewelry\.com\/[^"]+\/" \/>/', '', $buffer);
// 移除 en-US 和 en-GB 的 hreflang(多余)
$buffer = preg_replace('/<link rel="alternate" hreflang="en-US"[^>]*\/>/', '', $buffer);
$buffer = preg_replace('/<link rel="alternate" hreflang="en-GB"[^>]*\/>/', '', $buffer);
return $buffer;
});
}, 0);
add_action('wp_head', function() {
if (!is_singular('product')) return;
if (ob_get_level() > 0) ob_end_flush();
}, 999);
/**
* 修复 Rank Math BreadcrumbList 缺少 name 的问题
*/
add_filter('rank_math/schema/breadcrumb', function($data) {
if (empty($data['itemListElement']) || !is_array($data['itemListElement'])) {
return $data;
}
foreach ($data['itemListElement'] as $key => &$item) {
// 如果 item 是字符串(URL),转换为对象并添加 name
if (isset($item['item']) && is_string($item['item'])) {
$url = $item['item'];
$name = 'Home';
// 从 URL 提取路径作为名称
$path = parse_url($url, PHP_URL_PATH);
if (!empty($path) && $path !== '/') {
$path = trim($path, '/');
$segments = explode('/', $path);
$last = end($segments);
$name = ucwords(str_replace(['-', '_'], ' ', $last));
}
// 重新构造 item 为对象格式,包含 @id 和 name
$item['item'] = [
'@id' => $url,
'name' => $name
];
}
// 如果 item 是数组但缺少 name
elseif (isset($item['item']) && is_array($item['item']) && empty($item['item']['name'])) {
$item['item']['name'] = 'Page';
}
// 确保 ListItem 本身也有 name(双重保险)
if (empty($item['name'])) {
if (is_array($item['item']) && !empty($item['item']['name'])) {
$item['name'] = $item['item']['name'];
} else {
$item['name'] = 'Page';
}
}
}
return $data;
}, 999);
/* ============ MIRAMETAL Trade Registration & Subscribe Form ============ */
/**
* 输出前端 AJAX 变量 + 表单事件绑定(DOMContentLoaded 后执行)
*/
add_action('wp_head', 'mirametal_form_assets', 100);
function mirametal_form_assets() {
$ajax_url = admin_url('admin-ajax.php');
$nonce = wp_create_nonce('mirametal_form_nonce');
echo '<script>
window.MIRAMETAL_AJAX = {url: "' . esc_js($ajax_url) . '", nonce: "' . esc_js($nonce) . '"};
document.addEventListener("DOMContentLoaded", function(){
var md = document.getElementById("mm-md");
function openM(){ if(md){ md.style.display = "flex"; document.body.style.overflow = "hidden"; } }
function closeM(){ if(md){ md.style.display = "none"; document.body.style.overflow = ""; } }
var ob = document.getElementById("mm-open");
if(ob) ob.addEventListener("click", openM);
var cb = document.getElementById("mm-close");
if(cb) cb.addEventListener("click", closeM);
if(md) md.addEventListener("click", function(e){ if(e.target === md) closeM(); });
document.addEventListener("keydown", function(e){ if(e.key === "Escape") closeM(); });
function doSubmit(form, statusEl, type){
var btn = form.querySelector("button[type=submit]");
var fd = new FormData(form);
fd.append("action", "mirametal_form");
fd.append("type", type);
if(window.MIRAMETAL_AJAX){ fd.append("nonce", window.MIRAMETAL_AJAX.nonce); }
var url = (window.MIRAMETAL_AJAX && window.MIRAMETAL_AJAX.url) || "/wp-admin/admin-ajax.php";
btn.disabled = true; var old = btn.textContent; btn.textContent = "Sending…";
fetch(url, {method:"POST", body:fd, credentials:"same-origin"})
.then(function(r){ return r.json(); })
.then(function(res){
if(res && res.success){
statusEl.textContent = (type === "trade") ? "Thank you! We will reach out within 24 hours." : "Thank you for subscribing!";
statusEl.style.color = "#7fd17f";
form.reset();
} else {
statusEl.textContent = (res && res.data && res.data.message) || "Something went wrong. Please email mirametal@lhpv88.shop";
statusEl.style.color = "#e08b8b";
}
})
.catch(function(){
statusEl.textContent = "Network error. Please email mirametal@lhpv88.shop";
statusEl.style.color = "#e08b8b";
})
.finally(function(){ btn.disabled = false; btn.textContent = old; });
}
var f = document.getElementById("mm-form"), st = document.getElementById("mm-status");
if(f && st) f.addEventListener("submit", function(e){ e.preventDefault(); doSubmit(f, st, "trade"); });
var s = document.getElementById("mm-subscribe"), ss = document.getElementById("mm-sub-status");
if(s && ss) s.addEventListener("submit", function(e){ e.preventDefault(); doSubmit(s, ss, "subscribe"); });
});
</script>' . "\n";
}
/**
* AJAX 处理:询盘表单 + 订阅表单
*/
add_action('wp_ajax_mirametal_form', 'mirametal_form_handler');
add_action('wp_ajax_nopriv_mirametal_form', 'mirametal_form_handler');
function mirametal_form_handler() {
check_ajax_referer('mirametal_form_nonce', 'nonce');
$type = isset($_POST['type']) ? sanitize_text_field(wp_unslash($_POST['type'])) : 'trade';
// 订阅表单
if ($type === 'subscribe') {
$email = isset($_POST['email']) ? sanitize_email(wp_unslash($_POST['email'])) : '';
if (empty($email) || !is_email($email)) {
wp_send_json_error(array('message' => 'Please enter a valid email address.'));
}
$subject = 'New MIRAMETAL Newsletter Subscriber';
$body = "Email: {$email}\n\n-- MIRAMETAL Website";
$headers = array('Content-Type: text/plain; charset=UTF-8');
$sent = wp_mail('mirametal@lhpv88.shop', $subject, $body, $headers);
if ($sent) {
wp_send_json_success();
} else {
wp_send_json_error(array('message' => 'Subscription failed. Please email mirametal@lhpv88.shop.'));
}
return;
}
// 询盘表单
$name = isset($_POST['name']) ? sanitize_text_field(wp_unslash($_POST['name'])) : '';
$email = isset($_POST['email']) ? sanitize_email(wp_unslash($_POST['email'])) : '';
$country = isset($_POST['country']) ? sanitize_text_field(wp_unslash($_POST['country'])) : '';
$interest = isset($_POST['interest']) ? sanitize_text_field(wp_unslash($_POST['interest'])) : '';
$message = isset($_POST['message']) ? sanitize_textarea_field(wp_unslash($_POST['message'])) : '';
if (empty($name) || empty($email) || !is_email($email)) {
wp_send_json_error(array('message' => 'Please fill in your name and a valid email.'));
}
$subject = 'New Trade Inquiry from ' . $name;
$body = "Name: {$name}\nEmail: {$email}\nCountry/Region: {$country}\nInterested in: {$interest}\n\nMessage:\n{$message}\n\n-- MIRAMETAL Website";
$headers = array(
'Reply-To: ' . $name . ' <' . $email . '>',
'Content-Type: text/plain; charset=UTF-8',
);
$sent = wp_mail('mirametal@lhpv88.shop', $subject, $body, $headers);
if ($sent) {
wp_send_json_success(array('message' => 'Thank you!'));
} else {
wp_send_json_error(array('message' => 'Submission failed. Please email mirametal@lhpv88.shop.'));
}
}
/**
* Fix: Elementor "Product Page v2" template HTML widget uses esc_js() on price HTML,
* which double-escapes < > " and causes the page to render literal
* "<del aria-hidden=...>" text after a reset_image event instead of the proper
* <del> / <ins> tags. We patch this client-side by re-binding reset_image
* with a delayed handler that restores the correct HTML captured at page load.
*/
add_action("wp_footer", "mirametal_fix_product_price_box_html", 20);
function mirametal_fix_product_price_box_html() {
if (!function_exists("is_product") || !is_product()) return;
?>
<script>
(function(){
function mirametalRestorePriceBox(){
var pb = document.getElementById("productPriceBox");
if (!pb || !window._mirametalDefaultPriceHtml) return;
var cur = pb.innerHTML || "";
if (cur.indexOf("<del") !== -1 || cur.indexOf("<ins") !== -1) {
pb.innerHTML = window._mirametalDefaultPriceHtml;
}
}
function mirametalBind(){
if (!window.jQuery) { setTimeout(mirametalBind, 50); return; }
var jq = window.jQuery;
var pb = document.getElementById("productPriceBox");
if (pb) window._mirametalDefaultPriceHtml = pb.innerHTML;
jq("form.variations_form").on("reset_image.mirametal_fix", function(){
setTimeout(mirametalRestorePriceBox, 0);
});
jq("form.variations_form").on("found_variation.mirametal_fix", function(event, variation){
if (variation && variation.price_html) {
window._mirametalDefaultPriceHtml = variation.price_html;
}
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", mirametalBind);
} else {
mirametalBind();
}
})();
</script>
<?php
}
/**
* ============================================
* 强制将 WooCommerce 购物页面中文替换为英文
* 解决主题硬编码中文 / 翻译缓存问题
* ============================================
*/
// 1. 强制设置 WooCommerce 前台语言为英文
add_filter('locale', 'force_woocommerce_english_frontend', 999);
function force_woocommerce_english_frontend($locale) {
// 只在非后台(前台)生效,后台保持中文方便管理
if (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
return 'en_US';
}
return $locale;
}
// 2. 强制替换所有常见中文为英文(覆盖硬编码和翻译)
add_filter('gettext', 'force_translate_shop_chinese', 999, 3);
add_filter('ngettext', 'force_translate_shop_chinese', 999, 3);
function force_translate_shop_chinese($translated, $text, $domain) {
// 前台才替换
if (is_admin() && !(defined('DOING_AJAX') && DOING_AJAX)) {
return $translated;
}
// 定义替换字典:中文 => 英文
$replace = array(
// 购物页面常见词汇
'促销中' => 'On Sale',
'加入购物车' => 'Add to Cart',
'选择选项' => 'Select Options',
'添加到购物车' => 'Add to Cart',
'查看详情' => 'View Details',
'快速查看' => 'Quick View',
'比较' => 'Compare',
' wishlist' => 'Wishlist',
'收藏' => 'Wishlist',
// 排序和筛选
'推荐' => 'Recommend',
'默认排序' => 'Default sorting',
'按热门程度排序' => 'Sort by popularity',
'按评分排序' => 'Sort by average rating',
'按最新排序' => 'Sort by latest',
'按价格排序:从低到高' => 'Sort by price: low to high',
'按价格排序:从高到低' => 'Sort by price: high to low',
'显示' => 'Showing',
'个结果' => 'results',
'显示 1–' => 'Showing 1–',
'共' => 'of',
// 价格相关
'原价' => 'Regular price',
'售价' => 'Sale price',
'不含税' => 'excl. tax',
'含税' => 'incl. tax',
// Elementor 安全模式提示(截图右下角)
'开启安全模式' => 'Safe Mode Enabled',
'禁用安全模式' => 'Disable Safe Mode',
'已成功加载编辑器?' => 'Editor loaded successfully?',
'该问题很可能由您的某个插件或主题引起' => 'This issue is likely caused by a plugin or theme',
'单击此处进行故障排除' => 'Click here for troubleshooting',
'仍然遇到问题?' => 'Still having issues?',
// 分页
'上一页' => 'Previous',
'下一页' => 'Next',
// 面包屑
'首页' => 'Home',
'商店' => 'Shop',
'产品' => 'Products',
);
// 执行替换
if (isset($replace[$translated])) {
return $replace[$translated];
}
return $translated;
}
// 3. 用 JS 兜底替换(处理完全硬编码在 HTML 里的中文)
add_action('wp_footer', 'force_js_translate_chinese', 999);
function force_js_translate_chinese() {
if (is_admin()) return;
?>
<script>
(function() {
var dict = {
'促销中': 'On Sale',
'加入购物车': 'Add to Cart',
'选择选项': 'Select Options',
'开启安全模式': 'Safe Mode Enabled',
'禁用安全模式': 'Disable Safe Mode',
'已成功加载编辑器': 'Editor Loaded Successfully',
'该问题很可能由您的某个插件或主题引起': 'This issue is likely caused by a plugin or theme',
'单击此处进行故障排除': 'Click here for troubleshooting',
'仍然遇到问题?': 'Still having issues?',
'推荐': 'Recommend',
'显示': 'Showing',
'个结果': 'results',
'首页': 'Home',
'商店': 'Shop'
};
function replaceText(node) {
if (node.nodeType === 3) { // 文本节点
var text = node.nodeValue;
for (var cn in dict) {
if (text.indexOf(cn) !== -1) {
node.nodeValue = text.split(cn).join(dict[cn]);
}
}
} else {
for (var i = 0; i < node.childNodes.length; i++) {
replaceText(node.childNodes[i]);
}
}
}
// DOM 加载完成后执行
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function() {
replaceText(document.body);
});
} else {
replaceText(document.body);
}
// 监听动态加载的内容(如 AJAX 加载产品)
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
mutation.addedNodes.forEach(function(node) {
if (node.nodeType === 1) replaceText(node);
});
});
});
observer.observe(document.body, { childList: true, subtree: true });
})();
</script>
<?php
}
// 4. 清除 WooCommerce 翻译缓存
add_action('init', 'clear_wc_translation_cache');
function clear_wc_translation_cache() {
if (!is_admin()) {
// 禁用 WooCommerce 脚本翻译(防止加载中文 .json 翻译文件)
wp_dequeue_script('wc-cart-fragments');
wp_enqueue_script('wc-cart-fragments');
}
}
/* Change About menu link to Our Story */
add_action('wp_footer', function() {
echo '';
});
SEO keywords - MIRAMETAL
Skip to content
May 16, 2026
No Comments
Gemstone jewelry wholesale is the fastest-growing segment in silver right now. Customers want pieces with personality – colorful stones, unique combinations, jewelry that tells a story. What most guides will not tell you: the growth is in natural stones, not synthetic. And the suppliers who understand the difference are the ones making the margins. We
Read More »