<?php /** * Plugin Name: Loksifu Security and Performance * Description: Security headers, WP version removal, image lazy loading * Version: 1.0 */ // Security headers add_action('send_headers', 'loksifu_sec_headers'); function loksifu_sec_headers() { header('Strict-Transport-Security: max-age=31536000; includeSubDomains'); header('X-Content-Type-Options: nosniff'); header('X-Frame-Options: SAMEORIGIN'); header('Referrer-Policy: strict-origin-when-cross-origin'); header('X-XSS-Protection: 1; mode=block'); } // Cache-Control for static assets add_action('send_headers', 'loksifu_cache_headers'); function loksifu_cache_headers() { header('Cache-Control: public, max-age=3600'); } // Remove WordPress version generator tag remove_action('wp_head', 'wp_generator'); // Force lazy loading on images that don't have it add_filter('wp_content_img_tag', 'loksifu_img_lazy', 10, 3); function loksifu_img_lazy($img, $context, $attachment_id) { if (strpos($img, 'loading=') === false) { $img = str_replace('<img ', '<img loading="lazy" ', $img); } return $img; } // Also add lazy loading to post thumbnails add_filter('post_thumbnail_html', 'loksifu_thumb_lazy', 10); function loksifu_thumb_lazy($html) { if (strpos($html, 'loading=') === false) { $html = str_replace('<img ', '<img loading="lazy" ', $html); } return $html; } <?php /** * Plugin Name: Loksifu SEO and Optimization * Description: SEO meta tags, OG tags, schema, and performance tweaks * Version: 1.0 */ // Remove jQuery Migrate add_action('wp_default_scripts', function($scripts) { if (!is_admin() && isset($scripts->registered['jquery'])) { $script = $scripts->registered['jquery']; if ($script->deps) { $script->deps = array_diff($script->deps, ['jquery-migrate']); } } }); // Meta description add_action('wp_head', 'loksifu_meta_desc', 1); function loksifu_meta_desc() { if (is_front_page() || is_home()) { $desc = "駱法丹風水命理,香港專業風水玄學服務。提供種生基、家居風水、陰宅風水、辦公室風水、起名改名、六壬神功、和合、嬰靈超渡、擇日、紫微斗數及生肖運程等服務。"; } elseif (is_single() || is_page()) { $excerpt = get_the_excerpt(); $desc = $excerpt ? wp_strip_all_tags($excerpt) : wp_trim_words(wp_strip_all_tags(get_the_content()), 30); } elseif (is_category()) { $desc = single_cat_title('', false) . " - 駱法丹風水命理相關文章合集。"; } else { $desc = "駱法丹風水命理,香港專業風水玄學服務。"; } $desc = mb_substr($desc, 0, 160); if ($desc) { echo '<meta name="description" content="' . esc_attr($desc) . '">' . " "; } } // Open Graph tags add_action('wp_head', 'loksifu_og', 2); function loksifu_og() { echo '<meta property="og:locale" content="zh_HK">' . " "; echo '<meta property="og:site_name" content="駱法丹風水山堂">' . " "; if (is_front_page() || is_home()) { echo '<meta property="og:type" content="website">' . " "; echo '<meta property="og:title" content="駱法丹風水命理 | 香港專業風水玄學服務">' . " "; echo '<meta property="og:description" content="駱法丹風水命理,香港專業風水玄學服務。提供種生基、家居風水、陰宅風水、辦公室風水、起名改名等服務。">' . " "; echo '<meta property="og:url" content="' . esc_url(home_url('/')) . '">' . " "; } elseif (is_single() || is_page()) { echo '<meta property="og:type" content="article">' . " "; echo '<meta property="og:title" content="' . esc_attr(get_the_title()) . '">' . " "; echo '<meta property="og:url" content="' . esc_url(get_permalink()) . '">' . " "; if (has_post_thumbnail()) { echo '<meta property="og:image" content="' . esc_url(get_the_post_thumbnail_url(null, 'full')) . '">' . " "; } } } // Twitter cards add_action('wp_head', 'loksifu_twitter', 3); function loksifu_twitter() { echo '<meta name="twitter:card" content="summary_large_image">' . " "; } // Canonical URL add_action('wp_head', 'loksifu_canonical', 4); function loksifu_canonical() { if (is_front_page() || is_home()) { echo '<link rel="canonical" href="' . esc_url(home_url('/')) . '">' . " "; } elseif (is_single() || is_page()) { echo '<link rel="canonical" href="' . esc_url(get_permalink()) . '">' . " "; } } // JSON-LD structured data add_action('wp_head', 'loksifu_schema', 5); function loksifu_schema() { if (is_front_page() || is_home()) { $data = array( '@context' => 'https://schema.org', '@type' => 'ProfessionalService', 'name' => "駱法丹風水山堂", 'description' => "香港專業風水玄學服務,提供種生基、家居風水、陰宅風水、辦公室風水、起名改名、六壬神功等服務。", 'url' => home_url('/'), 'address' => array( '@type' => 'PostalAddress', 'addressCountry' => 'HK' ) ); echo '<script type="application/ld+json">' . json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>' . " "; } } // BreadcrumbList for single posts add_action('wp_head', 'loksifu_breadcrumb', 6); function loksifu_breadcrumb() { if (is_single()) { global $post; $cat = get_the_category($post->ID); $items = array( array('@type' => 'ListItem', 'position' => 1, 'name' => "首頁", 'item' => home_url('/')) ); if (!empty($cat)) { $items[] = array('@type' => 'ListItem', 'position' => 2, 'name' => $cat[0]->name, 'item' => get_category_link($cat[0]->term_id)); } $items[] = array('@type' => 'ListItem', 'position' => count($items) + 1, 'name' => get_the_title()); $schema = array('@context' => 'https://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => $items); echo '<script type="application/ld+json">' . json_encode($schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>' . " "; } } // Homepage title filter add_filter('pre_get_document_title', 'loksifu_title', 20); function loksifu_title($title) { if (is_front_page() || is_home()) { return "駱法丹風水命理 | 香港專業風水玄學服務"; } return $title; } // H1 fix - add screen-reader-text H1 for homepage when custom logo hides it add_action('wp_head', 'loksifu_h1_fix', 0); function loksifu_h1_fix() { if ((is_front_page() || is_home())) { echo '<h1 class="screen-reader-text">駱法丹風水命理 | 香港專業風水玄學服務</h1>' . " "; } } // Auto alt text via output buffering add_action('template_redirect', 'loksifu_alt_buffer_start'); function loksifu_alt_buffer_start() { ob_start('loksifu_alt_buffer_callback'); } function loksifu_alt_buffer_callback() { = esc_attr(get_bloginfo('name')); = preg_replace('/ alt=""/', ' alt="' . . '"', ); return ; }
Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/www.loksifu.cn/wp-content/plugins/loksifu-seo/loksifu-seo.php:1) in /www/wwwroot/www.loksifu.cn/wp-includes/sitemaps/class-wp-sitemaps-renderer.php on line 126
https://www.loksifu.cn/wp-sitemap-posts-post-1.xmlhttps://www.loksifu.cn/wp-sitemap-posts-page-1.xmlhttps://www.loksifu.cn/wp-sitemap-taxonomies-category-1.xmlhttps://www.loksifu.cn/wp-sitemap-taxonomies-post_tag-1.xmlhttps://www.loksifu.cn/wp-sitemap-users-1.xml