2026年9月3日
2026年9月3日
Hummingbirdのエラーを解決する方法
はじめに
Hummingbirdを有効にした後にキャッシュされたページが更新後も古い状態のまま表示される・CSS/JS最適化を有効にするとメニューやスライダーが表示されなくなる・Cloudflareと連携するとキャッシュが二重になりパージが正常に動作しない・ページキャッシュとブラウザキャッシュの設定が競合してサイトが遅くなるといった問題は、キャッシュパージ設定・アセット最適化の除外設定・CDN連携の設定が原因です。
症状・原因
- 記事を公開・更新してもフロントエンドには古い内容が表示される
- Hummingbirdのアセット最適化後に管理バーが消えるかCSSが崩れる
- Cloudflare CDNとの連携設定後にページが正しく表示されない
- Gravatarや外部リソースの読み込みが却って遅くなった
解決手順
ステップ1:Hummingbirdの状態を確認する
# Hummingbird設定確認
wp eval "
// Hummingbirdの有効化確認
if (defined('WPHB_VERSION')) {
echo 'Hummingbird version: ' . WPHB_VERSION . PHP_EOL;
}
// ページキャッシュ設定を確認
\$cache_module = WPHB_Module_Server::get_module('page-cache');
if (\$cache_module) {
\$options = \$cache_module->get_options();
echo 'Page cache: ' . (!empty(\$options['enabled']) ? 'enabled' : 'disabled') . PHP_EOL;
echo 'Cache logged in: ' . (!empty(\$options['logged_in']) ? 'yes' : 'no') . PHP_EOL;
echo 'Cache query strings: ' . (!empty(\$options['query_string']) ? 'yes' : 'no') . PHP_EOL;
echo 'Cache 404: ' . (!empty(\$options['cache_404']) ? 'yes' : 'no') . PHP_EOL;
}
// キャッシュファイルを確認
\$cache_dir = WP_CONTENT_DIR . '/wphb-cache/';
\$count = 0;
\$size = 0;
if (is_dir(\$cache_dir)) {
\$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(\$cache_dir));
foreach (\$iterator as \$file) {
if (\$file->isFile()) {
\$count++;
\$size += \$file->getSize();
}
}
}
printf('Cache files: %d (%s MB)' . PHP_EOL, \$count, round(\$size / 1024 / 1024, 2));
"
ステップ2:キャッシュパージをプログラムで制御する
// functions.php: Hummingbirdキャッシュ制御
// ① 投稿更新時にキャッシュをパージ
add_action('save_post', function(int $post_id, WP_Post $post): void {
if ($post->post_status !== 'publish') return;
if (wp_is_post_revision($post_id)) return;
// Hummingbirdのキャッシュクリア関数を呼び出す
if (function_exists('wphb_cache_flush_url')) {
wphb_cache_flush_url(get_permalink($post_id));
} elseif (class_exists('WPHB_Page_Cache')) {
WPHB_Page_Cache::clear_cache_for_post($post_id);
}
error_log(sprintf('[WPHB] Cache cleared for post #%d', $post_id));
}, 10, 2);
// ② コメント投稿時にキャッシュをパージ
add_action('comment_post', function(int $comment_id, int $comment_approved): void {
if (!$comment_approved) return;
$comment = get_comment($comment_id);
if ($comment && function_exists('wphb_cache_flush_url')) {
wphb_cache_flush_url(get_permalink($comment->comment_post_ID));
}
});
// ③ ウィジェット更新時に全キャッシュをクリア
add_action('update_option_widget_*', function(): void {
if (class_exists('WPHB_Page_Cache')) {
WPHB_Page_Cache::clear_all_cache();
error_log('[WPHB] All cache cleared due to widget update');
}
});
ステップ3:アセット最適化の除外設定を修正する
// functions.php: アセット最適化設定
// ① Hummingbirdのアセット最適化から除外するスクリプト
add_filter('wphb_minify_excluded_handles', function(array $excluded): array {
// 依存関係のあるスクリプトを除外
$to_exclude = [
'jquery',
'jquery-core',
'jquery-migrate',
'wp-embed',
'admin-bar', // 管理バー
'wc-cart-fragments', // WooCommerceカート
'slick',
'elementor-frontend',
];
return array_unique(array_merge($excluded, $to_exclude));
});
// ② 特定ページではアセット最適化を無効化
add_filter('wphb_should_minify', function(bool $should): bool {
// WooCommerceの動的ページでは最適化を無効化
if (function_exists('is_checkout') && (is_checkout() || is_cart())) {
return false;
}
// AMP対応ページでは無効化
if (function_exists('is_amp_endpoint') && is_amp_endpoint()) {
return false;
}
return $should;
});
// ③ インライン化するスクリプトのサイズ上限を調整
add_filter('wphb_minify_inline_script_size', function(int $size): int {
return 2048; // 2KB以下のスクリプトをインライン化
});
ステップ4:Cloudflare連携を修正する
# Cloudflare連携の診断
wp eval "
// Hummingbird CDN設定を確認
\$cdn_module = WPHB_Module_Server::get_module('cloudflare');
if (\$cdn_module) {
\$options = \$cdn_module->get_options();
echo 'Cloudflare enabled: ' . (!empty(\$options['enabled']) ? 'yes' : 'no') . PHP_EOL;
echo 'Zone ID set: ' . (!empty(\$options['zone_id']) ? 'yes' : 'no') . PHP_EOL;
echo 'API token set: ' . (!empty(\$options['api_token']) ? 'yes' : 'no') . PHP_EOL;
}
// Cloudflare APIに接続テスト
\$zone_id = get_option('wphb_cloudflare_zone_id', '');
\$api_token = get_option('wphb_cloudflare_api_token', '');
if (\$zone_id && \$api_token) {
\$response = wp_remote_get(
'https://api.cloudflare.com/client/v4/zones/' . \$zone_id,
['headers' => ['Authorization' => 'Bearer ' . \$api_token]]
);
if (!is_wp_error(\$response)) {
\$data = json_decode(wp_remote_retrieve_body(\$response), true);
echo 'Zone name: ' . (\$data['result']['name'] ?? 'not found') . PHP_EOL;
echo 'Zone status: ' . (\$data['result']['status'] ?? 'unknown') . PHP_EOL;
}
}
"
ステップ5:ブラウザキャッシュとパフォーマンス計測を設定する
// functions.php: ブラウザキャッシュ・計測設定
// ① 静的ファイルのブラウザキャッシュヘッダーをカスタマイズ
add_filter('wphb_browser_caching_htaccess_rules', function(string $rules): string {
$custom = '
# Hummingbird: Custom browser cache rules
<IfModule mod_headers.c>
<FilesMatch "\.(jpg|jpeg|png|gif|webp|svg|ico)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
<FilesMatch "\.(css|js)$">
Header set Cache-Control "public, max-age=604800"
</FilesMatch>
<FilesMatch "\.(woff|woff2|ttf|eot)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
</IfModule>
';
return $custom . $rules;
});
// ② パフォーマンステスト後にSlackへ通知
add_action('wphb_performance_test_completed', function(array $results): void {
$score = $results['score'] ?? 0;
if ($score < 70) {
wp_mail(
get_option('admin_email'),
sprintf('[%s] パフォーマンススコアが低下: %d点', get_bloginfo('name'), $score),
sprintf("Hummingbirdのパフォーマンスレポート:\n\nスコア: %d点\nFCP: %s\nLCP: %s\n\n改善が必要です。",
$score,
$results['fcp'] ?? 'N/A',
$results['lcp'] ?? 'N/A'
)
);
}
});
// ③ ログインユーザーにはキャッシュをバイパス
add_filter('wphb_page_cache_is_cacheable', function(bool $cacheable): bool {
if (is_user_logged_in()) return false;
if (is_admin()) return false;
return $cacheable;
});
注意事項
- Hummingbirdのアセット最適化(Minify)は一度に全てのオプションを有効にするのではなく、CSS集約→JS集約→遅延読み込みの順で一つずつ有効にしてサイトが正常に動作するか確認してください
- WPMU Devの有料プランを使用している場合、Hummingbirdのクラウド圧縮機能を有効にするとサーバー負荷を下げながらより強力な最適化が可能です。無料版ではローカル処理のみとなります
- WooCommerceを使用している場合、カートページと決済ページは必ずキャッシュ除外リストに追加してください。これらのページがキャッシュされるとセッション情報が正しく処理されません
まとめ
Hummingbird修復は①WPHB_Version・ページキャッシュ設定・キャッシュファイル数/サイズを確認、②save_postフックでwphb_cache_flush_url()またはWPHB_Page_Cache::clear_cache_for_post()を呼び出し自動パージ・コメント投稿時もパージ、③wphb_minify_excluded_handlesフィルターでjQuery・管理バー・WooCommerceカートを除外・wphb_should_minifyでチェックアウトページを除外、④CloudflareゾーンID・APIトークン設定確認・接続テストを実行、⑤wphb_browser_caching_htaccess_rulesで静的ファイルキャッシュルールをカスタマイズ・wphb_performance_test_completedでスコア低下時にメール通知する手順で解決します。