How to Create a PHP Test

A PHP Test lets you test with advanced functionality, logic, or hooks in your WordPress theme or plugins — without altering your site’s code directly. You can test different snippets of PHP that modify how your site behaves, giving you complete flexibility to optimize custom features, templates, or integrations.

⚠️ Note that that only users with the WordPress administrator role can create PHP tests.

Step 1: Create a New PHP Test

  • In your WordPress dashboard, go to Nelio A/B Testing → Tests.
  • Click Add Test.
  • In the dialog, select PHP (under the “Global” test category).
Test selector in Nelio A/B Testing

💡 PHP Tests are designed for developers and agencies who want to test advanced, backend-driven features that standard visual test types can’t reach — like custom hooks, server-side logic, or dynamic WooCommerce behavior. Make sure you have development access to your theme or custom codebase to understand which hooks or functions to modify.


Step 2: Name and Define Your Test

Give your test a clear, descriptive name (for example, “Free Shipping Threshold Logic” or “Custom Product Badge Function”).

In the right sidebar, you’ll find:

  • Status & Management: shows whether your test is Draft, Ready, Scheduled, or Paused, and allows you to define start/end dates.
  • Description: describe your goal and hypothesis (e.g., “We believe that showing a free shipping message for carts over $50 will increase conversion rate”).
  • Test Scope — defines where your test will run across the site. By default, PHP test variants are visible on all pages of your website. If you want to limit their scope, you can define which URLs the test should apply to using simple URL conditions (for example, “URL contains /checkout/”).
Defining a new PHP A/B test with Nelio A/B Testing

Define Scope in PHP

Alternatively, you can specify custom scope logic directly in PHP by clicking Define Scope in PHP. This opens the Code-Mirror based PHP scope editor, which lets you programmatically determine when your variants should run and where they should appear.

Define PHP Test scope

You can even choose when the scope code should execute — for example:

  • Run on "plugins_loaded" (early in the load process)
  • Run on "parse_query" (before WordPress determines which page to display)
  • Run on "wp" (after the main query has been set)
Screenshot of the scope in a PHP test, defined using some PHP code

This flexibility gives you precise control over how and when your test logic is applied

You can also enter a Preview URL to test your PHP logic before launching the test.


Step 3: Create and Edit PHP Variants

A PHP Test consists of one control (Variant A) and one or more custom PHP variants.

Each variant is executed dynamically when the test is active. To create a new variant:

  1. Click New Variant to duplicate the current setup.
  2. Rename each variant for clarity — for example, “ACF Product Summary” or ”Custom Badge Logic”.
  3. Click Edit to customize each variant. You can also click Preview, Duplicate, and Reset.

💡 Click New Variant to create a new alternative based on your current appearance, or use Duplicate under any existing variant to create a copy of that specific configuration.

PHP Variant Editor

When you edit a PHP variant, Nelio A/B Testing opens a PHP code editor with syntax highlighting (powered by CodeMirror). Write your PHP snippet inside this editor — it will be executed within a safe, sandboxed environment while the test is running.

You can use any WordPress hooks, filters, or theme functions. For example, you might want to customize WooCommerce product pages using an Advanced Custom Fields (ACF) field to replace the default summary text.

New PHP snippet in PHP test

Step 4: Define Goals and Conversion Actions

Every test needs a goal — what counts as success.

Each goal can include one or more conversion actions that describe the specific behavior you want to track.

Name your goals, then click the Add Action button to choose from the available conversion actions.

Defining a conversion goal


You can combine multiple actions under one goal.

CategoryExample Actions
ViewPage view, Element view
InteractionClick, Click external link, YouTube Video Playback, Scroll, Engagement
E-CommerceAdd WooCommerce product to cart, WooCommerce Purchase
OtherTime on Page, Custom event

🔍 Learn more: What Are the Conversion Actions and Goals? →


Step 5: Add Segmentation Rules (Optional)

Segmentation lets you decide who participates in the test. You can target visitors by conditions such as:

URL parameter · Referrer · Language · Location · Logged-in status · Visitor Type · Day/time · Browser · Device type · Operating system · Window Width · Cookie · IP address

If you skip segmentation, all visitors to the tested pages are included automatically.

🔍 Learn more What is Segmentation and How to Use It →


Step 6: Start the Test

When everything is ready:

  1. Review your setup summary at the top of the page.
  2. Click Start.

Nelio A/B Testing will:

  • Randomly assign visitors to variants.
  • Track conversions anonymously via Nelio Cloud.
  • Display real-time results in your dashboard.

⏯ Pause, Resume, or Stop Your Test

  • Pause a running test if you need to make changes, then resume it later.
  • Stop a test manually whenever you want, or let it end automatically under certain conditions such as duration, total number of visits or confidence results (available in Professional and Enterprise plans).
  • Once a test is stopped, its results remain available for review.
⚠️ Important note about editing paused tests

Editing a paused test may reset or affect ongoing statistics. When in doubt, duplicate the test before resuming.


Step 7: View Results and Analyze Performance

While your test runs, go to Nelio A/B Testing → Tests and click View Results to monitor its progress.

Summary of the results

In the right sidebar, you’ll find a quick overview of your test:

Goal selector – Choose which goal’s results to display.

Status icon – Indicates experiment status:

🟡 Collecting data.

🕒💛 Potential winner, low confidence

🟢🏅 Clear winner found.

🔴 No improvement over control.

Unique results – Filter duplicates.

Public results – Share a public link.

Export results – Download a CSV.

Summary – Shows status, duration, start date, and end condition.

Results in an A/B test with a winner variant

Test Progress

Evolution of an A/B test with one variant

The main area of the results page is divided into two tabs that visualize your test’s progress and performance:

  • Conversion Rates — A line chart showing conversion evolution across variants.
  • Views and Conversions — Compares total visits and conversions for each variant.

Confidence indicators appear alongside these charts, updating automatically as more data accumulates.

Below the charts, you’ll find a summary table with:

  • A thumbnail preview (if available) of each variant.
  • Number of visits and conversions.
  • Conversion rate and improvement over control.
PHP A/B Test results

Step 8: Improve Your Web Conversion

You can end a test manually using the Stop button in the upper-right corner of the results page, or let it end automatically based on the configured end mode.

After completing a test and identifying a clear winner, to manually integrate the winning code into your theme or plugin files to make the change permanent.

This ensures your high-performing changes become part of your permanent site experience.