• Resolved dimig

    (@dimig)


    Hey! I’m a newbie WP user, so please be kind.

    I’m using a premium stock theme. In order to reorder my header’s menus, I copy-pasted header.php into a child theme’s function.php and reordered the code.

    When I save the changes and try to reload the site, I’m given a fatal error message that ct_tracks_social_site_list() is undefined in a file.

    I tried copy-pasting the referenced file’s code into the child theme’s functions.php, too, but that just leads to more errors.

    Am I on the right track? If so …

    While I am somewhat familiar with coding, I don’t know PHP or WordPress. Are there some rules I have to obey when copying code from different files into the child theme’s functions.php file?

    Here is the code referenced by the undefined error: https://pastebin.com/ySCtE94q I’m not even using any of the social networks mentioned in the file anywhere on the site.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    The error message means the file that declares the function was not loaded for some reason. There’s always a chain of require or include statements ( or the *_once variants ) in various WP files that eventually load all the required code pages — there’s many dozens in every request!

    The undefined function error usually comes up when a browser requests a specific PHP file instead of going through the usual WP permalink system. You basically can’t do this without problems. Either make the requested PHP file a custom page template or use AJAX. A little used technique is to go through admin-post.php. There is no other workable option. You may see code examples online using wp-load.php or wp-blog-header.php. That can work but is strongly discouraged by those in the know.

    The only real rule for copying code is you cannot have the same function name defined more than once anywhere on any page involved with a request. Unless it’s pluggable, where the definition begins with if ( ! function_exists( 'function_name' ) )

    Thread Starter dimig

    (@dimig)

    Moving the code snippets from header.php around didn’t work, anyway. It just created a duplicate header. Removing the social code just resulted in a pluggable.php error. This is way over my head. I guess I’ll spend a few hundred dollars on someone. :/

    Thanks for the help, I learned some things. ??

    Marking as resolved.

    I really think that you will be able to fix your problem.
    The answer is NOT to copy the functions from header.php into your child theme’s functions.php, this is not how child themes work.
    Rather you copy the whole file “header.php” from your parent theme into your child theme directory, and customise it there. The child theme mechanism uses files from the child theme directory in preference to the parent theme.

    Thread Starter dimig

    (@dimig)

    I’ve decided to head in another direction now (creating a widget area above the header), but your suggestion has actually been super helpful in that regard, Ross. Thank you, I didn’t know other theme files could be copied there, too.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Reordering header elements with a child theme leads to undefined error’ is closed to new replies.