15. Adding Custom Schema Types | SEO Forge - Rank Higher with AI-Powered SEO
Download Log in

15. Adding Custom Schema Types

Developer Guide

Extend SEO Forge with custom JSON-LD schema blocks for post types or scenarios not covered by the built-in types.

Adding Schema via wp_head Hook

To add additional schema blocks alongside SEO Forge output (without replacing it), hook into wp_head at a priority after SEO Forge’s schema output (priority 5):

php
// Add Event schema for a custom post type
add_action( 'wp_head', function () {
    if ( ! is_singular( 'event' ) ) {
        return;
    }

    $post_id = get_the_ID();
    $schema  = [
        '@context'  => 'https://schema.org',
        '@type'     => 'Event',
        'name'      => get_the_title( $post_id ),
        'startDate' => get_post_meta( $post_id, '_event_start', true ),
        'endDate'   => get_post_meta( $post_id, '_event_end', true ),
        'location'  => [
            '@type' => 'Place',
            'name'  => get_post_meta( $post_id, '_event_venue', true ),
            'address' => [
                '@type'           => 'PostalAddress',
                'streetAddress'   => get_post_meta( $post_id, '_event_address', true ),
                'addressLocality' => get_post_meta( $post_id, '_event_city', true ),
            ],
        ],
    ];

    echo '<script type="application/ld+json">'
       . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT )
       . '</script>' . "n";
}, 7 );

SoftwareApplication Schema for Downloads

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

    $post_id = get_the_ID();
    $schema  = [
        '@context'              => 'https://schema.org',
        '@type'                 => 'SoftwareApplication',
        'name'                  => get_the_title( $post_id ),
        'operatingSystem'       => 'Windows, macOS, Linux',
        'applicationCategory'   => 'DeveloperApplication',
        'offers' => [
            '@type'         => 'Offer',
            'price'         => '0',
            'priceCurrency' => 'USD',
        ],
    ];

    echo '<script type="application/ld+json">'
       . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT )
       . '</script>' . "n";
}, 7 );

Course Schema for LMS Plugins

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

    $post_id = get_the_ID();
    $schema  = [
        '@context'    => 'https://schema.org',
        '@type'       => 'Course',
        'name'        => get_the_title( $post_id ),
        'description' => get_the_excerpt(),
        'provider'    => [
            '@type' => 'Organization',
            'name'  => get_bloginfo( 'name' ),
            'sameAs' => home_url(),
        ],
        'hasCourseInstance' => [
            '@type'      => 'CourseInstance',
            'courseMode'  => 'online',
            'instructor' => [
                '@type' => 'Person',
                'name'  => get_the_author_meta( 'display_name', get_post_field( 'post_author', $post_id ) ),
            ],
        ],
    ];

    echo '<script type="application/ld+json">'
       . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT )
       . '</script>' . "n";
}, 7 );

Forge AI Assistant Online

Hi! I'm the SEO Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs