Live Blog

WordPress header.php, ACF the_field() and PHP 8.1 results in Uncaught Error: Call to undefined function get_field()

This was a strange one after moving from PHP 7.4 to PHP 8.0. and PHP 8.1 I ran into an issue where the Advanced Custom Fields plugin function the_field() resulted in the following error.

Uncaught Error: Call to undefined function get_field() in /var/www/wp-content/themes/theme/header.php:146

The get_field() was in header.php and, as such, should be working, but I realized that perhaps the plugin isn’t loaded at this stage. So, I added the following to the top of the header.php file.

 // Include acf.php
include_once(ABSPATH.'wp-content/plugins/advanced-custom-fields-pro/acf.php');

And the error went away! The get_field was defined due to the Advanced Custom Fields plugin being included. I don’t know why this happened when switching to PHP 8.1

0 Shares: