# Paywalled Content Structured Data

> Marks members-only posts as not free with isAccessibleForFree and the CSS class of the gated section, so Google does not treat the hidden part as cloaking.

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

## Code

```php
// Categories whose posts are paywalled, and the class of the gated section.
$wpide_paywall_categories = array( 'premium' );
$wpide_paywall_class      = 'paywall';

add_action( 'wp_head', function () use ( $wpide_paywall_categories, $wpide_paywall_class ) {
    if ( ! is_singular( 'post' ) || ! has_category( $wpide_paywall_categories, get_queried_object_id() ) ) {
        return;
    }

    $post = get_queried_object();
    $data = array(
        '@context'            => 'https://schema.org',
        '@type'               => 'NewsArticle',
        '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 ) ),
        'isAccessibleForFree' => false,
        'hasPart'             => array(
            '@type'               => 'WebPageElement',
            'isAccessibleForFree' => false,
            'cssSelector'         => '.' . sanitize_html_class( $wpide_paywall_class ),
        ),
    );

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

## Notes

Wrap the members-only part of the content in an element with the paywall class. If your SEO plugin already outputs Article schema, this adds a second, compatible Article node.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Paywalled Content Structured Data" 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/
