0

I am creating my first WordPress theme for personal use, when I added main function in functions.php, website showing an warning on top.

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'myfirsttheme_setup ' not found or invalid function name in G:\wamp64\www\mysite\wp-includes\class-wp-hook.php on line 287.

Should I define myfirsttheme_setup function first? If yes, then how?

My code is here:

<?php /** * @package myfirsttheme * @since myfirsttheme */ if ( ! function_exists( 'myfirsttheme_setup' ) ) : /** * support post thumbnails. */ function myfirsttheme_setup() { add_theme_support( 'custom-header' ); add_theme_support('menus'); add_theme_support('post-thumbnails'); add_theme_support( 'automatic-feed-links' ); add_theme_support( 'title-tag' ); add_theme_support( 'customize-selective-refresh-widgets' ); } endif; // myfirsttheme_setup add_action( 'after_setup_theme', 'myfirsttheme_setup' ); 
1
  • Hi Mukesh, can I suggest that when putting up a question that you show that you've read the existing documentation. I'm sure you have - but its a good idea to take time out to show that you have by providing a couple of links. In this case the answer to your question is here, in the WordPress themes documentation: developer.wordpress.org/themes/basics/theme-functions/… Commented Jul 2, 2020 at 6:09

1 Answer 1

2

The code you entered is correct. myfirsttheme_setup just needs to be defined before the after_setup_theme action hook is executed. It does not need to be defined when you add the hook. The action hook will just store the string in $wp_filter global and then call call_user_func_array at execution of the hook. Your issue must be somewhere else. I would search for myfirsttheme_setup throughout your entire install. You have to be trying to hook to it before it's defined or changing myfirsttheme_setup to not be callable in another place.

You do always have the option of making it an anonymous function as well.

add_action('after_setup_theme', function () { add_theme_support('custom-header'); add_theme_support('menus'); add_theme_support('post-thumbnails'); add_theme_support('automatic-feed-links'); add_theme_support('title-tag'); add_theme_support('customize-selective-refresh-widgets'); }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.