3

I am newbie in web development. I am discovering wordpress templates now. They all have similar structure. But I have noticed one interesting thing for me.
There are function calls in php template files. Like get_header(), get_footer(). But I don't understand how does PHP interpreter know about this functions, there are not any includes,requires ....
How does this work, please explain this. I would be very grateful for any help.

5 Answers 5

3

Take a look at the files starting with index.php in the Wordpress folder, which is the first file that get's loaded. You will see "require( dirname( __FILE__ ) . '/wp-blog-header.php' );", and that's just the beginning.

So to answer your question, wordpress uses "require" to include files.

Sign up to request clarification or add additional context in comments.

4 Comments

I guess I should add this line or it is added automaticly while installing in wordpress, I have been discovering bare template, not installed, so I couldn't find this require declaration. Am I right ?
It's all automatic. You should never have to add these lines. Wordpress searches for certain files in certain folders, and just adds them when required.
So the bare template, downloaded from the internet doesn't have this line, but when installing template through admin panel, wordpress automaticly adds require line as the first line of index.php, right ?
No. I edited my previous comment. Wordpress will just search for certain files such as custom templates, and they get included automatically. The template files get included after the wordpress core files, so they are not needed in each and every template file.
1

Read the docs:

...
get_header() is located in wp-includes/general-template.php.

Source: http://codex.wordpress.org/Function_Reference/get_header

...
get_footer() is located in wp-includes/general-template.php.

Source: http://codex.wordpress.org/Function_Reference/get_footer

You may be able to get help on WordPress Development.

Comments

0

The php template files itself are included somewhere. For example:

function get_header() { /* ... */ }
include("page.php");

Comments

0

All the functions that are in a wordpress theme have been declared somewhere else in the core code of Wordpress before the template is loaded.

Comments

0
get_header() 

is defined in wp-includes/general-template.php.

So how is wp-includes/general-template.php included?

wp-settings.php requires wp-includes/general-template.php.
wp-config.php requires wp-settings.php.
wp-load.php requires wp-config.php.
wp-blog-header.php requires wp-load.php.
index.php requires wp-blog-header.php.

Every page request starts by loading index.php.

If you are using Linux, you can find references to file by using grep. E.g.

grep -r "function get_header(" *

returns a list of files where the get_header() function is defined.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.