26. A/B Testing | SEO Forge - Rank Higher with AI-Powered SEO
Download Log in

26. A/B Testing

Developer Guide

Time-based meta title/description rotation for SEO split testing. Unlike visitor-based tools, SEO Forge uses weekly time-based rotation to ensure search engines always see a consistent version (avoiding cloaking penalties). PRO feature.

How It Works

  1. Test starts immediately when enabled
  2. Week 1: Variant A (original meta title/description) is served
  3. Week 2: Variant B (alternate meta title/description) is served
  4. Alternates weekly until disabled
  5. Google always sees ONE consistent version at any given time

The variant is determined by: floor((time() - start_time) / WEEK_IN_SECONDS) % 2 — when 0, variant A is active; when 1, variant B.

Implementation Details

On wp_head (priority 0, before all meta output):

  • SEOFORGE_AB_Testing::maybe_swap_meta checks if A/B testing is enabled
  • If variant B is active, title is overridden via document_title_parts filter
  • Description B replaces the primary tag
  • Impression counters are incremented (_seoforge_ab_served_a or _seoforge_ab_served_b)

Programmatic Control

php
$post_id = 42;

// Start an A/B test
update_post_meta( $post_id, '_seoforge_ab_enabled', true );
update_post_meta( $post_id, '_seoforge_ab_title_b', 'Alternative Title | MyBlog' );
update_post_meta( $post_id, '_seoforge_ab_desc_b', 'Alternative description for testing.' );
update_post_meta( $post_id, '_seoforge_ab_start', time() );
update_post_meta( $post_id, '_seoforge_ab_served_a', 0 );
update_post_meta( $post_id, '_seoforge_ab_served_b', 0 );

// Check current state
$current = get_post_meta( $post_id, '_seoforge_ab_current', true ); // 'a' or 'b'
$served_a = (int) get_post_meta( $post_id, '_seoforge_ab_served_a', true );
$served_b = (int) get_post_meta( $post_id, '_seoforge_ab_served_b', true );

// Declare a winner and keep variant B
$title_b = get_post_meta( $post_id, '_seoforge_ab_title_b', true );
$desc_b  = get_post_meta( $post_id, '_seoforge_ab_desc_b', true );
update_post_meta( $post_id, '_seoforge_meta_title', $title_b );
update_post_meta( $post_id, '_seoforge_meta_description', $desc_b );
update_post_meta( $post_id, '_seoforge_ab_enabled', false );

// Bulk-stop all running A/B tests
$active = get_posts( [
    'post_type' => 'any', 'posts_per_page' => -1, 'fields' => 'ids',
    'meta_query' => [ [ 'key' => '_seoforge_ab_enabled', 'value' => '1' ] ],
] );
foreach ( $active as $pid ) {
    update_post_meta( $pid, '_seoforge_ab_enabled', false );
}

Analyzing Test Results

php
// Compare variant performance using impression counts
$post_id  = 42;
$served_a = (int) get_post_meta( $post_id, '_seoforge_ab_served_a', true );
$served_b = (int) get_post_meta( $post_id, '_seoforge_ab_served_b', true );
$start    = (int) get_post_meta( $post_id, '_seoforge_ab_start', true );
$weeks    = floor( ( time() - $start ) / WEEK_IN_SECONDS );

echo "Test running for {$weeks} weeksn";
echo "Variant A served: {$served_a} timesn";
echo "Variant B served: {$served_b} timesn";

// For CTR analysis, combine with GSC data
if ( class_exists( 'SEOFORGE_GSC' ) && SEOFORGE_GSC::instance()->is_connected() ) {
    $page_url = get_permalink( $post_id );
    $rankings = SEOFORGE_GSC::instance()->get_page_rankings( $page_url, 28 );
    // Compare CTR during variant A vs variant B periods
}

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