با درج دادههای عنوان، تاریخها و مشخصات نویسنده در قالب اسکیمای `Article` در هک `wp_head` برای مقالات، تأییدیه کامل گوگل را دریافت کنید.
<?php
/**
* تولید خودکار اسکیمای غنی مقاله (Article) با فرمت مدرن JSON-LD
*/
function bisco_output_article_schema() {
if ( ! is_single() || 'post' !== get_post_type() ) {
return;
}
global $post;
$author_id = $post->post_author;
$thumbnail_url = has_post_thumbnail( $post->ID ) ? get_the_post_thumbnail_url( $post->ID, 'full' ) : home_url( '/default-share.jpg' );
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'Article',
'mainEntityOfPage' => array(
'@type' => 'WebPage',
'@id' => esc_url( get_permalink( $post ) ),
),
'headline' => esc_html( get_the_title( $post ) ),
'image' => array(
esc_url( $thumbnail_url ),
),
'datePublished' => get_the_date( 'c', $post ),
'dateModified' => get_the_modified_date( 'c', $post ),
'author' => array(
'@type' => 'Person',
'name' => esc_html( get_the_author_meta( 'display_name', $author_id ) ),
'url' => esc_url( get_author_posts_url( $author_id ) ),
),
'publisher' => array(
'@type' => 'Organization',
'name' => get_bloginfo( 'name' ),
'logo' => array(
'@type' => 'ImageObject',
'url' => esc_url( home_url( '/logo.png' ) ),
),
),
'description' => esc_html( wp_strip_all_tags( get_the_excerpt( $post ) ) ),
);
echo '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) . '</script>' . "
";
}
add_action( 'wp_head', 'bisco_output_article_schema', 4 );