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

4. A/B Testing Meta Fields

Developer Guide

Time-based meta title/description rotation fields. PRO feature.

Meta KeyTypeDescription
_seoforge_ab_enabledboolWhether an A/B test is currently active on this post.
_seoforge_ab_title_bstringVariant B title text. Variant A is the regular _seoforge_meta_title or template.
_seoforge_ab_desc_bstringVariant B meta description text.
_seoforge_ab_startint (timestamp)Unix timestamp when the test started. Used to calculate weekly variant rotation.
_seoforge_ab_currentstring ('a' or 'b')The currently active variant (recalculated on each page load).
_seoforge_ab_served_aintNumber of impressions (page loads) served for variant A.
_seoforge_ab_served_bintNumber of impressions (page loads) served for variant B.
php
// ----- Starting an A/B test programmatically -----

$post_id = 42;

update_post_meta( $post_id, '_seoforge_ab_enabled', true );
update_post_meta( $post_id, '_seoforge_ab_title_b', 'Alternative SEO Title for A/B Testing' );
update_post_meta( $post_id, '_seoforge_ab_desc_b', 'This is the alternative description being tested.' );
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 );
php
// ----- Reading A/B test status -----

$post_id = 42;

$enabled = get_post_meta( $post_id, '_seoforge_ab_enabled', true );
$variant = get_post_meta( $post_id, '_seoforge_ab_current', true );
$start   = (int) get_post_meta( $post_id, '_seoforge_ab_start', true );
$weeks   = floor( ( time() - $start ) / WEEK_IN_SECONDS );

$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 );

// Calculate which variant should be active right now
$calculated_variant = ( $weeks % 2 === 0 ) ? 'a' : 'b';

// Stop A/B test and keep the winner
update_post_meta( $post_id, '_seoforge_ab_enabled', false );

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