<?php
declare(strict_types=1);
if ( ! defined( 'ABSPATH' ) ) { exit; }
/**
 * Meta Tags — OGP & Twitter Card.
 * @package WTE_Business_Card
 */
function wte_output_meta_tags(): void {
	$title = get_bloginfo( 'name' );
	$desc  = get_theme_mod( 'wte_meta_description', get_bloginfo( 'description' ) );
	$image = get_theme_mod( 'wte_og_image', '' );
	$url   = get_permalink() ?: home_url( '/' );

	if ( $desc ) {
		echo '<meta name="description" content="' . esc_attr( $desc ) . '">' . PHP_EOL;
	}
	echo '<meta property="og:title" content="' . esc_attr( $title ) . '">' . PHP_EOL;
	echo '<meta property="og:description" content="' . esc_attr( $desc ) . '">' . PHP_EOL;
	echo '<meta property="og:url" content="' . esc_url( $url ) . '">' . PHP_EOL;
	echo '<meta property="og:type" content="website">' . PHP_EOL;
	echo '<meta property="og:site_name" content="' . esc_attr( $title ) . '">' . PHP_EOL;
	if ( $image ) {
		echo '<meta property="og:image" content="' . esc_url( $image ) . '">' . PHP_EOL;
		echo '<meta property="og:image:width" content="1200">' . PHP_EOL;
		echo '<meta property="og:image:height" content="630">' . PHP_EOL;
	}
	echo '<meta name="twitter:card" content="summary_large_image">' . PHP_EOL;
	echo '<meta name="twitter:title" content="' . esc_attr( $title ) . '">' . PHP_EOL;
	echo '<meta name="twitter:description" content="' . esc_attr( $desc ) . '">' . PHP_EOL;
	if ( $image ) {
		echo '<meta name="twitter:image" content="' . esc_url( $image ) . '">' . PHP_EOL;
	}
}
add_action( 'wp_head', 'wte_output_meta_tags', 5 );
