# Article Structured Data for Posts

> Outputs BlogPosting schema (JSON-LD) on single posts with the headline, dates, author, image and publisher.

- Type: PHP
- Runs: Frontend only
- Category: [SEO](https://wpide.com/library/category/seo/)
- Tags: seo, schema, json-ld, articles
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/article-schema/

## Code

```php
add_action( 'wp_head', function () {
    if ( ! is_singular( 'post' ) ) {
        return;
    }

    $post = get_queried_object();

    $data = array(
        '@context'         => 'https://schema.org',
        '@type'            => 'BlogPosting',
        'headline'         => wp_strip_all_tags( get_the_title( $post ) ),
        'datePublished'    => get_the_date( DATE_W3C, $post ),
        'dateModified'     => get_the_modified_date( DATE_W3C, $post ),
        'mainEntityOfPage' => get_permalink( $post ),
        'author'           => array(
            '@type' => 'Person',
            'name'  => get_the_author_meta( 'display_name', $post->post_author ),
            'url'   => get_author_posts_url( $post->post_author ),
        ),
        'publisher'        => array(
            '@type' => 'Organization',
            'name'  => get_bloginfo( 'name' ),
        ),
    );

    if ( has_post_thumbnail( $post ) ) {
        $data['image'] = get_the_post_thumbnail_url( $post, 'full' );
    }

    echo '<script type="application/ld+json">' . wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG ) . "</script>\n";
} );
```

## Notes

Skip this snippet if an SEO plugin already outputs article schema.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Article Structured Data for Posts" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
