@charset "UTF-8";
/*
    Template: swell
    Theme Name: SWELL CHILD
    Theme URI: https://swell-theme.com/
    Description: SWELLの子テーマ
    Version: 1.0.0
    Author: LOOS WEB STUDIO
    Author URI: https://loos-web-studio.com/

    License: GNU General Public License
    License URI: http://www.gnu.org/licenses/gpl.html
*/
// 記事下に免責事項を自動挿入
add_filter('the_content', function ($content) {
    if (!is_singular('post')) {
        return $content;
    }

    // 免責文（ここを書き換えてOK）
    $disclaimer = '
    <div class="investment-disclaimer" style="margin-top:40px; padding:20px; border:1px solid #ddd; font-size:0.9em;">
        <strong>【免責事項】</strong><br>
        本記事の内容は情報提供のみを目的としており、特定の金融商品や投資行動を推奨するものではありません。<br>
        投資に関する最終判断は、必ずご自身の責任と判断で行ってください。<br>
        本サイトは、掲載情報に基づいて生じたいかなる損失・損害についても一切の責任を負いかねます。
    </div>
    ';

    return $content . $disclaimer;
});

// 記事ページに NewsArticle の構造化データを自動出力
add_action('wp_head', function () {
    if (!is_singular('post')) return;

    global $post;
    $title         = get_the_title($post);
    $description   = wp_strip_all_tags(get_the_excerpt($post));
    $url           = get_permalink($post);
    $datePublished = get_the_date('c', $post);
    $dateModified  = get_the_modified_date('c', $post);
    $author        = get_the_author_meta('display_name', $post->post_author);
    $image         = get_the_post_thumbnail_url($post, 'full');

    // サイトロゴ取得
    $logo_id = get_theme_mod('custom_logo');
    $logo_url = $logo_id ? wp_get_attachment_image_url($logo_id, 'full') : '';

    $data = [
        "@context"        => "https://schema.org",
        "@type"           => "NewsArticle",
        "headline"        => $title,
        "description"     => $description,
        "url"             => $url,
        "datePublished"   => $datePublished,
        "dateModified"    => $dateModified,
        "author"          => [
            "@type" => "Person",
            "name"  => $author,
        ],
        "publisher"       => [
            "@type" => "Organization",
            "name"  => get_bloginfo('name'),
            "logo"  => [
                "@type" => "ImageObject",
                "url"   => $logo_url,
            ],
        ],
        "mainEntityOfPage" => $url,
    ];

    if ($image) {
        $data["image"] = $image;
    }

    echo '<script type="application/ld+json">' . json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>';
});