Skip to main content

Fix the notice _load_textdomain_just_in_time was called incorrectly for ACF.

If you set DEBUG mode to true you might see an error like so:

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the acf domain was triggered too early

If you’re adding ACF Options to your theme and have the code below, the notice will be triggered

The cause: ACF Options Page

The following code shows how ACF options pages were registered – by calling the function directly. This causes the error to show and took me some good debugging to find it.

<?php
if ( function_exists( 'acf_add_options_page' ) ) {
	// Add a global website options page.
	acf_add_options_page(
		array(
			'page_title' => __( 'Website Options' ),
			'menu_title' => __( 'Website Options' ),
		)
	);
}
Code language: PHP (php)

The Solution

Instead, you need to wrap the code in the acf/init hook:

/**
 * Add an options page for ACF.
 *
 * @return void
 */
function weba_acf_add_options_page() {
	if ( function_exists( 'acf_add_options_page' ) ) {
		acf_add_options_page(
			array(
				'page_title' => __( 'Website Options' ),
				'menu_title' => __( 'Website Options' ),
			)
		);
	}
}
add_action( 'acf/init', 'weba_acf_add_options_page' );Code language: PHP (php)
Privacy Overview

This website uses cookies so that I can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to my website to help me to understand which sections of the website you find most interesting and useful.