// === SEO 增强代码 开始 === // 1. 旧URL 301重定向(处理数字ID的旧链接) function farsailing_redirect_old_urls() { if (is_admin()) return; $request_uri = $_SERVER['REQUEST_URI']; // 匹配 /数字.html 或 /数字/ 格式 if (preg_match('#^/\d+\.html?$#', $request_uri) || preg_match('#^/(\d+)/?$#', $request_uri, $matches)) { $post_id = isset($matches[1]) ? intval($matches[1]) : intval(basename($request_uri, '.html')); if ($post_id > 0) { $post = get_post($post_id); if ($post && $post->post_status === 'publish') { wp_redirect(get_permalink($post_id), 301); exit; } } } } add_action('template_redirect', 'farsailing_redirect_old_urls', 1); // 2. 自定义Meta描述 function farsailing_meta_description() { global $post; $description = ''; if (is_singular()) { if (!empty($post->post_excerpt)) { $description = wp_trim_words(wp_strip_all_tags($post->post_excerpt), 30, ''); } else { $description = wp_trim_words(wp_strip_all_tags($post->post_content), 30, ''); } } elseif (is_category() || is_tag()) { $description = category_description(); if (!$description) $description = single_cat_title('', false) . ' - 鹿鸣网创'; } elseif (is_home() || is_front_page()) { $description = '鹿鸣网创 - 专注电商运营、自媒体运营、网络创业培训,提供京东、淘宝、抖音、小红书等平台运营实战课程。'; } if ($description) { echo '' . "\n"; } } add_action('wp_head', 'farsailing_meta_description', 1); // 3. Open Graph + Twitter Card + Schema JSON-LD function farsailing_social_meta() { global $post; if (is_singular()) { $title = get_the_title(); $url = get_permalink(); $site_name = get_bloginfo('name'); $excerpt = !empty($post->post_excerpt) ? $post->post_excerpt : wp_trim_words($post->post_content, 25); $excerpt = wp_strip_all_tags($excerpt); $image = ''; if (has_post_thumbnail()) { $image = get_the_post_thumbnail_url($post->ID, 'large'); } if (!$image) { $image = 'https://www.farsailing.cn/wp-content/uploads/logo.png'; } $type = is_singular('post') ? 'article' : 'website'; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; // Article Schema if (is_singular('post')) { $schema = array( '@context' => 'https://schema.org', '@type' => 'Article', 'headline' => $title, 'description' => $excerpt, 'datePublished' => get_the_date('c'), 'dateModified' => get_the_modified_date('c'), 'author' => array( '@type' => 'Person', 'name' => get_the_author() ), 'publisher' => array( '@type' => 'Organization', 'name' => $site_name, 'url' => home_url() ), 'mainEntityOfPage' => $url ); if ($image) { $schema['image'] = $image; } echo '' . "\n"; } } } add_action('wp_head', 'farsailing_social_meta', 2); // 4. 站点 Schema function farsailing_site_schema() { if (is_home() || is_front_page()) { $schema = array( '@context' => 'https://schema.org', '@type' => 'WebSite', 'name' => get_bloginfo('name'), 'description' => get_bloginfo('description'), 'url' => home_url(), 'potentialAction' => array( '@type' => 'SearchAction', 'target' => home_url('/?s={search_term_string}'), 'query-input' => 'required name=search_term_string' ) ); echo '' . "\n"; $org_schema = array( '@context' => 'https://schema.org', '@type' => 'Organization', 'name' => '鹿鸣网创', 'url' => home_url(), 'logo' => 'https://www.farsailing.cn/wp-content/uploads/logo.png' ); echo '' . "\n"; } } add_action('wp_head', 'farsailing_site_schema', 3); // 5. 自动添加文章图片ALT function farsailing_auto_image_alt($alt, $image_id) { if (empty($alt)) { $alt = get_the_title($image_id); if (empty($alt)) { $alt = get_the_title(); } } return $alt; } add_filter('wp_get_attachment_image_attributes', function($attr, $attachment) { if (empty($attr['alt'])) { $title = get_the_title($attachment->ID); $attr['alt'] = $title ? $title : get_the_title(); } return $attr; }, 10, 2); // 6. 防止WordPress自动添加的rest_output_link导致SEO问题 remove_action('wp_head', 'rest_output_link_wp_head', 10); remove_action('wp_head', 'wp_oembed_add_discovery_links', 10); // 7. 优化canonical URL function farsailing_canonical_url() { if (is_singular()) { global $post; $canonical = get_permalink($post->ID); echo '' . "\n"; } } add_action('wp_head', 'farsailing_canonical_url', 4); // === SEO 增强代码 结束 ===
Fatal error: Uncaught Error: Call to undefined function tb_xzh_head_var() in /www/wwwroot/www.farsailing.cn/wp-content/themes/zibll/header.php:25 Stack trace: #0 /www/wwwroot/www.farsailing.cn/wp-includes/template.php(684): require_once() #1 /www/wwwroot/www.farsailing.cn/wp-includes/template.php(643): load_template() #2 /www/wwwroot/www.farsailing.cn/wp-includes/general-template.php(45): locate_template() #3 /www/wwwroot/www.farsailing.cn/wp-content/themes/zibll/404.php(14): get_header() #4 /www/wwwroot/www.farsailing.cn/wp-includes/template-loader.php(74): include('/www/wwwroot/ww...') #5 /www/wwwroot/www.farsailing.cn/wp-blog-header.php(19): require_once('/www/wwwroot/ww...') #6 /www/wwwroot/www.farsailing.cn/index.php(17): require('/www/wwwroot/ww...') #7 {main} thrown in /www/wwwroot/www.farsailing.cn/wp-content/themes/zibll/header.php on line 25