<?php if ( !defined( 'ABSPATH' ) ) exit;//PHPの宣言と直接アクセスの拒否

function haup_add_website_schema() {
	$site_title = get_bloginfo('name');
	$site_cach = get_bloginfo('description');
	$homeurl = home_url();
	$searchurl = home_url('/?s={search_term_string}');

		// パブリッシャーロゴ情報情報
		$pub_image_data = haup_schema_pub_image_data_callback();

	if (is_front_page()) {
		$schema = [
			"@context" => "https://schema.org",
			"@type" => "WebSite",
			"name" => esc_html( $site_title ),
			"url" => esc_url( $homeurl ),
			"description" => esc_html( $site_cach ),
			"potentialAction" => [
				"@type" => "SearchAction",
				"target" => [
					"@type" => "EntryPoint",
					"urlTemplate" => esc_url( $searchurl )
				],
			"query-input" => "required name=search_term_string"
			],
			"publisher" => [
				"@type" => "Organization",
				"name" => esc_html(haup_top_archive_schema_output_site_owner()),
				"url" => esc_url(haup_top_archive_schema_output_site_owner_url()),
				"logo" => [
					"@type" => "ImageObject",
					"url" => $pub_image_data['url'],
					"width" => $pub_image_data['width'],
					"height" => $pub_image_data['height']
				],
				"sameAs" => [
					haup_top_archive_schema_output_sns_url_callback()
				]
			]
		];

		echo '<!-- HAUP Schema Data for Frontpage -->';
		echo "\n";//HTML上で改行
		// JSON_PRETTY_PRINT を使うことで、HTMLソース上で整形されて出力される
		//echo '<script type="application/ld+json">' . json_encode($schema, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>';
		echo '<script type="application/ld+json">' . json_encode($schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>';
	}
}
add_action('wp_head', 'haup_add_website_schema', 3);