PHPackages                             builtnorth/wp-schema - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. builtnorth/wp-schema

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

builtnorth/wp-schema
====================

Comprehensive schema generation for WordPress with SEO optimization and logo support

v1.1.0(8mo ago)14031[1 PRs](https://github.com/builtnorth/wp-schema/pulls)GPL-2.0-or-laterPHPPHP &gt;=8.1CI passing

Since Jul 21Pushed 8mo agoCompare

[ Source](https://github.com/builtnorth/wp-schema)[ Packagist](https://packagist.org/packages/builtnorth/wp-schema)[ RSS](/packages/builtnorth-wp-schema/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (6)Used By (0)

WP Schema Framework
===================

[](#wp-schema-framework)

A comprehensive, WordPress schema generation framework with a clean provider-based architecture.

Architecture
------------

[](#architecture)

WP Schema follows a clean, modular architecture:

- **Core Framework**: Provider registration, schema assembly, and output management
- **Provider System**: Hook-based registration for extensible schema generation
- **Clean References**: Schema graphs with @id references and automatic deduplication
- **WordPress Integration**: Deep integration with WordPress core data and features
- **@graph Format**: Modern JSON-LD output using Google's recommended @graph structure

Features
--------

[](#features)

- **Simple Provider Interface**: Easy to implement schema providers
- **Comprehensive Coverage**: Built-in providers for all major WordPress contexts
- **Registration Priority System**: Predictable schema ordering with priority-based registration
- **Flexible Filtering**: Multiple filter hooks for customization at every level
- **Reference Resolution**: Clean @id references for building complex schema graphs
- **WordPress Core Integration**: Automatic schema for posts, pages, archives, media, and more
- **Type Registry**: Comprehensive registry of 250+ schema.org types with UI support

Installation
------------

[](#installation)

```
# Via Composer
composer require builtnorth/wp-schema
```

Quick Start
-----------

[](#quick-start)

Initialize the framework in your plugin or theme:

```
// Initialize wp-schema
if (class_exists('BuiltNorth\WPSchema\App')) {
	add_action('init', function() {
		BuiltNorth\WPSchema\App::initialize();
	});
}
```

Once initialized, the framework automatically outputs schema via HTML `` tags in the document head.

### For Plugin Developers

[](#for-plugin-developers)

Register your schema providers via hook:

```
add_action('wp_schema_framework_register_providers', function($provider_manager) {
    $provider_manager->register(
        'my_plugin_provider',
        'MyPlugin\\Schema\\MySchemaProvider'
    );
});
```

### Simple Filter Approach

[](#simple-filter-approach)

For basic schema additions:

```
add_filter('wp_schema_framework_pieces', function($pieces, $context) {
    if ($context === 'singular' && get_post_type() === 'event') {
        $pieces[] = [
            '@type' => 'Event',
            'name' => get_the_title(),
            'startDate' => get_post_meta(get_the_ID(), 'event_date', true)
        ];
    }
    return $pieces;
}, 10, 2);
```

### Schema Type Override

[](#schema-type-override)

Override the schema type for specific posts:

```
add_filter('wp_schema_framework_post_type_override', function($type, $post_id, $post_type, $post) {
    if (get_post_meta($post_id, 'page_type', true) === 'contact') {
        return 'ContactPage';
    }
    return $type;
}, 10, 4);
```

### Product Schema Integration

[](#product-schema-integration)

The ProductProvider automatically detects WooCommerce, Easy Digital Downloads, and BigCommerce products.

**Note**: To avoid conflicts, ProductProvider automatically disables itself when WooCommerce's built-in schema is active. To force wp-schema to handle product schema instead:

```
// Disable WooCommerce's built-in structured data
add_filter('woocommerce_structured_data_disable', '__return_true');

// Or tell wp-schema that WooCommerce schema is not active
add_filter('wp_schema_framework_woocommerce_schema_active', '__return_false');
```

You can also integrate custom e-commerce solutions:

```
// Mark custom post type as product
add_filter('wp_schema_framework_is_product', function($is_product, $post_id, $context) {
    return get_post_type($post_id) === 'my_product_type';
}, 10, 3);

// Provide product data for custom e-commerce
add_filter('wp_schema_framework_get_product_data', function($data, $post_id) {
    if (get_post_type($post_id) !== 'my_product_type') {
        return $data;
    }

    return [
        'name' => get_the_title($post_id),
        'price' => get_post_meta($post_id, 'price', true),
        'currency' => 'USD',
        'availability' => 'https://schema.org/InStock',
        'sku' => get_post_meta($post_id, 'sku', true),
        'brand' => get_post_meta($post_id, 'brand', true),
        'aggregateRating' => [
            'ratingValue' => get_post_meta($post_id, 'rating', true),
            'reviewCount' => get_post_meta($post_id, 'review_count', true),
        ],
    ];
}, 10, 2);
```

### Event Schema Integration

[](#event-schema-integration)

The EventProvider automatically detects The Events Calendar, Events Manager, Modern Events Calendar, and Event Organiser. You can also integrate custom event solutions:

```
// Mark custom post type as event
add_filter('wp_schema_framework_is_event', function($is_event, $post_id, $context) {
    return get_post_type($post_id) === 'my_event_type';
}, 10, 3);

// Provide event data for custom events
add_filter('wp_schema_framework_get_event_data', function($data, $post_id) {
    if (get_post_type($post_id) !== 'my_event_type') {
        return $data;
    }

    return [
        'name' => get_the_title($post_id),
        'description' => get_the_excerpt($post_id),
        'startDate' => get_post_meta($post_id, 'event_start', true), // ISO 8601 format
        'endDate' => get_post_meta($post_id, 'event_end', true),
        'eventStatus' => 'https://schema.org/EventScheduled',
        'eventAttendanceMode' => 'https://schema.org/OfflineEventAttendanceMode',
        'location' => [
            'name' => get_post_meta($post_id, 'venue_name', true),
            'address' => [
                'streetAddress' => get_post_meta($post_id, 'venue_address', true),
                'addressLocality' => get_post_meta($post_id, 'venue_city', true),
                'addressRegion' => get_post_meta($post_id, 'venue_state', true),
                'postalCode' => get_post_meta($post_id, 'venue_zip', true),
            ],
            'type' => 'Place'
        ],
        'offers' => [
            'price' => get_post_meta($post_id, 'ticket_price', true),
            'currency' => 'USD',
            'availability' => 'https://schema.org/InStock',
        ],
    ];
}, 10, 2);
```

Provider Interface
------------------

[](#provider-interface)

Create schema providers by implementing `SchemaProviderInterface`:

```
