// === SEO + Performance Optimization (2026-10-01) ===
add_action('wp_head', function() {
// Description 默认值(按页面类型覆盖)
if (is_front_page()) {
$desc = 'YRJC — China sourcing, purchasing, inspection, logistics & general trading. One accountable partner, one contract under Chinese law.';
} elseif (is_page('contact')) {
$desc = 'Request a free quote from YRJC. China sourcing, purchasing, inspection, factory visits. WhatsApp & email response within 24 hours.';
} elseif (is_page('about')) {
$desc = 'About YRJC — Zhuhai Hengqin Yiri Jingcheng Trading Co., Ltd. China-based sourcing partner for international B2B procurement.';
} elseif (is_singular('page')) {
$desc = wp_strip_all_tags(get_the_excerpt());
$desc = $desc ? mb_substr($desc, 0, 155) : 'YRJC — China sourcing & trading partner.';
} else {
$desc = 'YRJC — Your trusted partner for China sourcing, purchasing, inspection, logistics & general trading.';
}
$desc = esc_attr($desc);
$title = wp_get_document_title();
$url = esc_url(home_url(add_query_arg([], $GLOBALS['wp']->request)));
$img = esc_url(home_url('/wp-content/uploads/2026/09/yrjc-logo.svg'));
// Meta description
echo '' . "\n";
// Open Graph
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
// Twitter Card
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
// Robots
echo '' . "\n";
// Favicon + Apple touch icon
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
// Preconnect / DNS prefetch
echo '' . "\n";
echo '' . "\n";
if (is_front_page()) {
echo '' . "\n";
echo '' . "\n";
}
// Sitemap link
echo '' . "\n";
// Theme color (mobile browser address bar)
echo '' . "\n";
echo '' . "\n";
// Organization Schema.org (homepage only)
if (is_front_page()) {
echo '' . "\n";
}
});
// Auto-add loading="lazy" to images that don't have it (except first image)
add_filter('the_content', function($content) {
if (is_admin() || empty($content)) return $content;
// Add loading=lazy to all img tags except first
$count = 0;
$content = preg_replace_callback(
'/]*?)>/i',
function($m) use (&$count) {
$attrs = $m[1];
// Skip if already has loading attribute
if (preg_match('/\bloading\s*=/i', $attrs)) return $m[0];
// Skip first image (above the fold)
$count++;
if ($count <= 2) return $m[0];
// Add loading=lazy and decoding=async
return '
';
},
$content
);
return $content;
}, 99);