/**
Theme Name: Astra Child
Author: Brainstorm Force
Author URI: http://wpastra.com/about/
Description: Astra is the fastest, fully customizable & beautiful theme suitable for blogs, personal portfolios and business websites. It is very lightweight (less than 50KB on frontend) and offers unparalleled speed. Built with SEO in mind, Astra comes with schema.org code integrated so search engines will love your site. Astra offers plenty of sidebar options and widget areas giving you a full control for customizations. Furthermore, we have included special features and templates so feel free to choose any of your favorite page builder plugin to create pages flexibly. Some of the other features: # WooCommerce Ready # Responsive # Compatible with major plugins # Translation Ready # Extendible with premium addons # Regularly updated # Designed, Developed, Maintained & Supported by Brainstorm Force. Looking for a perfect base theme? Look no further. Astra is fast, fully customizable and beautiful theme!
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: astra-child
Template: astra
*/
/**
 * お問い合わせページ以外で reCAPTCHA を読み込まない
 */
add_action( 'wp_enqueue_scripts', function() {
    // お問い合わせページ（スラッグが contact）以外の場合
    if ( ! is_page( 'contact' ) ) {
        wp_dequeue_script( 'google-recaptcha' );
        wp_dequeue_script( 'wpcf7-recaptcha' );
    }
}, 100 );

// AstraのGoogleフォント読み込みを「swap」に設定する
add_filter( 'astra_google_font_display', function( $display ) {
    return 'swap';
} );

/**
 * 最初の1枚の画像だけ「遅延読み込み」をオフにして優先度を上げる
 * これにより LCP (メイン画像の表示) が劇的に速くなります
 */
add_filter( 'wp_min_priority_img_index', function() {
    return 1; // 最初の1枚は遅延読み込みしない
});

/**
 * 最初の画像に fetchpriority="high" を付与する
 */
add_filter( 'wp_get_attachment_image_attributes', function( $attrs, $attachment, $size ) {
    static $count = 0;
    if ( is_front_page() && $count === 0 ) {
        $attrs['fetchpriority'] = 'high';
        $attrs['decoding'] = 'sync'; // 同期的にデコード（表示）させる
    }
    $count++;
    return $attrs;
}, 10, 3 );

/**
 * Google Analytics (GA4) 計測コード
 */
add_action( 'wp_head', function() {
?>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-LF7X183MPF"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-LF7X183MPF');
</script>
<?php
}, 1);
