/* ===== SEO 基础设施:canonical + meta description + Organization Schema ===== */
add_action('wp_head', function () {
global $wp;
$url = home_url($wp->request);
$title = wp_get_document_title();
$desc = '';
if (is_front_page()) {
$desc = get_bloginfo('description') ?: get_bloginfo('name') . ' - ' . get_bloginfo('description');
} elseif (is_singular()) {
$desc = get_the_excerpt();
} elseif (is_archive()) {
$desc = get_the_archive_description();
}
if (is_singular()) {
$pid = get_queried_object_id();
$custom = get_post_meta($pid, '_leijex_page_lead', true);
if ($custom) $desc = $custom;
$yoast = get_post_meta($pid, '_yoast_wpseo_metadesc', true);
$aio = get_post_meta($pid, '_aioseo_description', true);
if ($aio) $desc = $aio;
if ($yoast) $desc = $yoast;
}
/* canonical */
$canon = $url;
if (is_singular()) {
$canon = get_permalink();
}
echo ' ' . "\n";
/* meta description fallback */
if ($desc && strpos($html_buffer ?? '', 'name="description"') === false) {
echo ' ' . "\n";
}
/* Organization + WebSite Schema(仅首页) */
if (is_front_page()) {
$org = array(
'@context' => 'https://schema.org',
'@type' => 'Organization',
'name' => get_bloginfo('name'),
'url' => home_url('/'),
);
$logo = get_theme_mod('custom_logo');
if ($logo) {
$logo_data = wp_get_attachment_image_src($logo, 'full');
if ($logo_data) $org['logo'] = $logo_data[0];
}
echo '' . "\n";
$web = array(
'@context' => 'https://schema.org',
'@type' => 'WebSite',
'name' => get_bloginfo('name'),
'url' => home_url('/'),
);
echo '' . "\n";
}
/* BreadcrumbList Schema(非首页) */
if (!is_front_page() && function_exists('leijex_breadcrumb')) {
// 简化 BreadcrumbList
$items = array();
$items[] = array('@type' => 'ListItem', 'position' => 1, 'name' => 'Home', 'item' => home_url('/'));
if (is_singular('product')) {
$items[] = array('@type' => 'ListItem', 'position' => 2, 'name' => 'Products', 'item' => home_url('/products/'));
$items[] = array('@type' => 'ListItem', 'position' => 3, 'name' => get_the_title());
} elseif (!is_front_page()) {
$items[] = array('@type' => 'ListItem', 'position' => 2, 'name' => get_the_title());
}
if (count($items) > 1) {
$bl = array('@context' => 'https://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => $items);
echo '' . "\n";
}
}
}, 2);
Warning : Cannot modify header information - headers already sent by (output started at /usr/share/nginx/html/leijex-wp/wp-content/themes/leijex/inc/seo-base.php:1) in /usr/share/nginx/html/leijex-wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Sitemap/Sitemap.php on line 405
Warning : Cannot modify header information - headers already sent by (output started at /usr/share/nginx/html/leijex-wp/wp-content/themes/leijex/inc/seo-base.php:1) in /usr/share/nginx/html/leijex-wp/wp-content/plugins/all-in-one-seo-pack/app/Common/Sitemap/Sitemap.php on line 406