Call to undefined function create_function() 📝 WordPress

WordPress on PHP 8: Fatal error: Uncaught Error: Call to undefined function create_function() / each()

An old plugin/theme uses functions removed in PHP 8 (create_function, each), so the site breaks after a PHP upgrade.

Seen on: WordPress

Meaning

create_function and each() were deprecated in PHP 7.2 and removed in 8.0. Abandoned plugins/themes crash on modern hosting. Update or replace them; patching uses closures/foreach.

Common causes

  • Outdated plugin/theme with PHP 5-era code
  • Host upgraded PHP to 8.x
  • Custom code in functions.php

⚡ Quick fix

  1. Update the plugin/theme or replace it
  2. Temporarily switch PHP back while you fix it
  3. Rewrite create_function as an anonymous function

Detailed fix by platform

PHP

  1. php
    // old: add_action('widgets_init', create_function('', 'return register_widget("My_Widget");'));
    add_action('widgets_init', function () { register_widget('My_Widget'); });

How to diagnose

  1. File — Which plugin/theme?
  2. PHP — Version upgrade recently?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.