Support Log in

42. Integration with WooCommerce SEO

Developer Guide
Prefer video? Watch the Rank Forge tutorials 9 short guides covering every feature Watch

Rank Forge automatically detects WooCommerce products and generates Product schema. This section covers advanced integration patterns.

Automatic Product Schema

When WooCommerce is active and a product post type is detected, Rank Forge auto-generates Product schema:

php
// Rank Forge auto-detects 'product' post type and generates:
// @type: Product, with name, description, image, offers (price, availability), brand

Custom Product Meta Templates

php
update_option( 'rankforge_title_templates', [
    'product' => [
        'title'       => 'Buy {{title}} {{separator}} {{siteName}}',
        'description' => '{{excerpt}} | Free shipping on orders over $50.',
    ],
] );

Including Products in the Sitemap

Products need no setup to appear in the sitemap. The sitemap index lists every public post type except attachments that has a published post, so the WooCommerce product post type, which is public, is listed with its own sitemap at /product-sitemap.xml. Products that WooCommerce hides from search results, and products set to noindex, are left out of that sitemap. The enabled_types key of rankforge_sitemap_settings is ignored, so adding product to it changes nothing.

To leave products out of the sitemap, switch off “Show in search results” for the product post type in the Title Templates card of the Settings screen. In code, that switch is the noindex flag of the post type in the rankforge_posttype_robots option, so it also sets the post type to noindex:

php
// Leave the product post type out of the sitemap (this also sets it to noindex)
$robots = get_option( 'rankforge_posttype_robots', [] );
$robots['product'] = [ 'noindex' => true ];
update_option( 'rankforge_posttype_robots', $robots );

// Flush cache so the change shows immediately
RANKFORGE_Sitemap::instance()->invalidate_cache();

Enhancing Product Schema with WooCommerce Data

php
add_action( 'wp_head', function () {
    if ( ! is_singular( 'product' ) || ! function_exists( 'wc_get_product' ) ) {
        return;
    }

    $product = wc_get_product( get_the_ID() );
    if ( ! $product ) {
        return;
    }

    $schema = [
        '@context' => 'https://schema.org',
        '@type'    => 'Product',
        'name'     => $product->get_name(),
        'sku'      => $product->get_sku(),
        'offers'   => [
            '@type'         => 'Offer',
            'price'         => $product->get_price(),
            'priceCurrency' => get_woocommerce_currency(),
            'availability'  => $product->is_in_stock()
                ? 'https://schema.org/InStock'
                : 'https://schema.org/OutOfStock',
        ],
    ];

    // Add aggregate rating if reviews exist
    if ( $product->get_review_count() > 0 ) {
        $schema['aggregateRating'] = [
            '@type'       => 'AggregateRating',
            'ratingValue' => $product->get_average_rating(),
            'reviewCount' => $product->get_review_count(),
        ];
    }

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

—

Forge AI Assistant Online

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

Just now
Powered by Forge AI · Browse docs