'', 'a' => '', ), $atts, 'acsaiv_faq' ); $question = trim( (string) $atts['q'] ); $answer = trim( (string) $atts['a'] ); if ( '' === $question || '' === $answer ) { return ''; } $this->items[] = array( 'q' => $question, 'a' => $answer, ); wp_enqueue_style( 'acsaiv-faq' ); // スキーマと表示内容の一致が必須のため、可視のQ&Aを必ず出力する。 return sprintf( '

Q. %s

A. %s

', esc_html( $question ), esc_html( $answer ) ); } public function output_schema() { if ( empty( $this->items ) ) { return; } $entities = array(); foreach ( $this->items as $item ) { $entities[] = array( '@type' => 'Question', 'name' => $item['q'], 'acceptedAnswer' => array( '@type' => 'Answer', 'text' => $item['a'], ), ); } $schema = array( '@context' => 'https://schema.org', '@type' => 'FAQPage', 'mainEntity' => $entities, ); // スラッシュはエスケープしたまま出力する("" を含む値でのタグ突破を防ぐ)。 printf( '', wp_json_encode( $schema, JSON_UNESCAPED_UNICODE ) ); } }