← All Articles A Product of Kinsa Creative

A/B or Multivariate Testing a Design in WordPress Using an ACF Field as a Manual Trigger

In this example, we're using an ACF field assigned to a taxonomy to manually control whether a specific taxonomy is rendered using the original design or an alternate design.

Add the ACF Field

Edit the ACF Field Group applied to the taxonomy (or create one). Add a new True/False field named Alternate Design. The Field Name should autopopulate to alternate_design.

Change the Body Class Based on the ACF Field Value

In the WordPress functions.php file, use that ACF field to hook into the body class:

add_filter("body_class", "custom_body_class");

function custom_body_class($classes) {
    if ( is_tax( 'my-taxonomy' ) ) {
        $queried_object = get_queried_object();

        if ( get_field( 'alternate_design', $queried_object ) ) {
            $classes[] = 'alternate';
        } else {
            $classes[] = 'default';
        }
    }

    return $classes;
}

Now, that can be styled by targeting body.alternate.

If/Else in the Template Depending on the ACF Field Value

The template markup can be changed by checking for the same applied filter:

$queried_object = get_queried_object();
if ( isset( $queried_object ) && get_field( 'alternate_design', $queried_object ) ) { ... }

Feedback?

Email us at enquiries@kinsa.cc.