<?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/pluggable.php on line 1535
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/pluggable.php on line 1538