Return the current visitor’s variant key for an experiment, or null if they are unassigned or in holdout.
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.
File: includes/experiments/wpd-experiment-functions.php
Line: ~51
wpdai_get_experiment_variant( string $experiment_slug ): string|null
| Parameter | Type | Required | Description |
|---|---|---|---|
| $experiment_slug | string | Yes | A/B test slug from the A/B Test editor. |
Type: string|null
Description: Variant key such as control or treatment, or null when the visitor is not in that experiment (including holdout).
$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 ) . '"';
}
wp.null, not a variant key. Do not treat null as control unless that is an explicit product decision.wpdai_in_experiment() is clearer.