While working on a theme I encountered the following error:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ” not found or invalid function name in /path/to/themesite/wp-includes/plugin.php on line 403
At first I thought it was because of the way I’m building the theme. You may remember I’ve mentioned
core a few times.
core is a library I built to help speed HTML development. I have a class that makes building head elements very easy. The “problem” is that wordpress requires you to call the
wp_head function on the head of your templates. I solved this by including a method on the class that can be used to call any function.
My first reaction was to change my header.php file for the one included on the twentyeleven theme, but the problem did not get solved. This hinted me that the problem was not in the way I was calling
wp_head. Once I realized that, I started commenting parts of the code out. I have a line of code that takes care of including a file, which in turn includes a few more files. Each file adds a certain feature to the theme, like custom header, or background color. Commenting out the line that includes the first file solved the problem.
Once I realized that the problem was in one of the files that was being included which add features to the theme, I went on and started commenting out individual
include lines to see which feature was causing the problem. This way I found out that the feature causing the problem was the custom background feature.
That file had the following code:
//Custom Background documentation: http://codex.wordpress.org/Custom_Backgrounds $color = '1d1d1d'; $defaults = array( 'default-color' => $color, 'default-image' => '', 'wp-head-callback' => '', 'admin-head-callback' => '', 'admin-preview-callback' => '' ); add_theme_support('custom-background', $defaults); ?>
As you can see, the
wp-head-callback is empty. Which was causing the problem, since this callback gets registered somewhere in wordpress, and then wordpress tries to call this callback, but it is empty. If you review the source code of
add_theme_support you will see that it has a default callback. In this case, you have to either specify a call back or do not include that array element at all.
This is a pretty simple error, but it took me a good 20 minutes to figure out.
Comic by XKCD