• Hi everyone,

    As the title says… I have just changed the name of the file, “home.php” to “home2.php” and then got this weird error message:

    Fatal error: Call to undefined function get_header() in home2.php on line 16

    And when I commented that line 16… I also got a simialr error but for the get_footer() function this time.

    So, my best guess for this error is that it’s messing the includes of those functions… even though there was no include statement(s) when it was home.php.

    Is there another file that is including those functions definitions in home.php?? (like a config file or something)

    If yes, where is that file so that I can assign to it the job of helping and including those get_header() and get_footer() to my new home2.php.

    Do not ask me why did I change the name from home.php to home2.php, please.

    I do want to know how the structure of those includes are based in wordpress. I appreciate the powerful tool I have, thank you. But I still need to be the master of it so I can modify any bit I want! ??

    Still, any thoughts are welcomed!

    Thanks for reading.

Viewing 6 replies - 1 through 6 (of 6 total)
  • where exactly is this home2.php? Is it in your theme?

    wp-content -> themes -> your_theme -> home2.php ??

    Thread Starter buhamad

    (@buhamad)

    yes… you guessed it right.

    Hm… I’m not sure why changing the name would kick up those errors…

    But it may have something to do with how your particular theme is configured. What theme are you using?

    home.php does a very specific thing… it has a function based on the name. home2.php would not have that function. I’m not sure that adding a 2 to the name should cause any issue, but under what circumstances are you using the template? Because wp wouldn’t natively go hunting for a file named home2.php, so you must be using it a certain way for it to be called….

    You’re probably already familiar with how templates are called, but just in case
    https://codex.www.ads-software.com/Template_Hierarchy

    And then to understand the includes
    https://codex.www.ads-software.com/Include_Tags

    I’m just not sure what, in your situation, would be blocking the includes from working. That should only happen if you are somehow visiting the template without the WP environment being loaded….

    Thread Starter buhamad

    (@buhamad)

    “wp wouldn’t natively go hunting for a file named home2.php”

    yea… true… it’s all configured to be home.php.. not home2.php

    My question is: where is that configuration file?
    I want to be in control of it… not it controlling me :/

    That configuration file is making the includes implicitly.. I admit that this method is modular inorder to fit with the fact wp uses various themes, indeed..

    Still, again, I want to control the includes structure of my own website.. with the help of wp, of course ??

    any other help, please?

    https://core.trac.www.ads-software.com/browser/tags/3.3.1/wp-includes/general-template.php

    so wp-includes -> general-template.php is where the includes get defined.

    I’m still trying to figure out how you are using home2.php, because no matter the name of the template, if you are using a file within WP, get_header will always load the header, and not come back as undefined. Unless you are doing something outside of WP, in which case the definitions wouldn’t be laoded, you’d have to include the WP environment.

    NOTE: By linking that file above, I’m most certainly not encouraging any editing of core WP files, which is a big no no, and causes much grief and gnashing of teeth!

    Thread Starter buhamad

    (@buhamad)

    I tried to edit the core of WP before… missed up everything back then… lool

    Here is what I tried now…
    I fetched the definition of all needed functions manually and copied them literally into my new home2.php …

    As u said, get_header() is in “wp-includes/general-template.php” indeed (so as get_footer())

    Sadly enough, those two functions are also using other wp function from other php files inside wp-includes!

    Sooooo…. I continued copying (load-template(), …etc)… until I reached those two functions, require() and require_once(), and got long-description errors….

    So I called it a truce until some other time :/

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Changing the home.php page to home2.php… undefined function get_header() ?!?’ is closed to new replies.