Function: wpdai_get_experiment_variant

Return the current visitor’s variant key for an experiment, or null if they are unassigned or in holdout.

Description

Use this when you need the key itself (for logging, CSS classes, or switching among more than two Pro arms) instead of a yes/no check. It reads the assignment already applied on the request.

Location

File: includes/experiments/wpd-experiment-functions.php

Line: ~51

Function Signature

wpdai_get_experiment_variant( string $experiment_slug ): string|null

Parameters

Parameter Type Required Description
$experiment_slug string Yes A/B test slug from the A/B Test editor.

Return Value

Type: string|null

Description: Variant key such as control or treatment, or null when the visitor is not in that experiment (including holdout).

Example Usage

$variant = function_exists( 'wpdai_get_experiment_variant' )
    ? wpdai_get_experiment_variant( 'pricing-headline' )
    : null;

if ( 'treatment' === $variant ) {
    add_filter( 'the_title', 'my_treatment_title' );
}

if ( $variant ) {
    echo 'class="exp-pricing-' . esc_attr( $variant ) . '"';
}

Notes

Related