tags:

views:

150

answers:

6

Specifically in theme php files, such as say index.php. The very first thing in most theme's index.php file is a call to get_header() which is most certainly not not defined in index.php, so how does it know about that function?

I'm not very familiar with php, but from what I've read just now there is an include and require keyword which work more or less the same way as an import in Java or include in C, which I understand and makes sense. However, the only usage of these keywords in this particular index.php file includes a file that doesn't contain a definition of get_header(), nor does it have any includes or requires of its own (though it does call some more functions it has no right to know about, much like index) so clearly that's now how it knows about this function.

Anyway, I was just hoping to remove some of the 'magic' from wordpress for myself. Thanks in advance!

+1  A: 

Most likely, index.php is being included in another file and that file either defines the get_header() function or - more likely - contains yet another included php file which in turns defines the get_header() function.

You have to understand that the php include and require functions behave like an in-line include. It simply treats the include file as being part of the original script.. a big concatenated script (so not really like an import in Java)

You may want to start at the .htaccess file which will tell you which .php file is assigned to handle the request. Based on what you said in your question, it will probably not be index.php. When you find the top-most php script, you can work your way from there with the includes and requires..

Miky Dinescu
Whoops, you are correct about it not being similar to java import, thanks for pointing that out!
Trajanus
A: 

in c and in java you declare the import at the top of you files. In php you can set the includes almost anyware you want.

so this is valid:

<?php 
// define some functions
?>
<html>
<head>
<?php
include('head.php');
?>
</head>
<body></body></html>

it is possible that these get_header() methods are declared somewhere before the index.php page is included.

If you want to leave out the <?php get_header(); ?> then there will be no problem

Robert Cabri
+4  A: 

Themes' index.php file is not the main file that's processed, that one resides in the root directory of your wordpress installation. It calls several files setting up the environment and then loads the template. You might want to look in the wp-content/plugins directory, maybe starting with the globals.php file to tweak some of the magic.

Also the wp-includes directory contains interesting files, the get_header() function is defined in general-template.php in that directory.

kemp
Thanks! Exactly the sort of answer I was looking for :)
Trajanus
+2  A: 

Specifically in theme php files, such as say index.php. The very first thing in most theme's index.php file is a call to get_header() which is most certainly not not defined in index.php, so how does it know about that function?

A theme's index.php file is never executed on its own. All requests to a WordPress install go through the main WordPress index.php file.

ceejayoz
+4  A: 

The index.php in each theme isn't ever called directly, rather those are included by other files in Wordpress.

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

The templates files are loaded by require_once function calls in the load_template function of wp-includes/theme.php

jimdahl
A: 

Take a look at all the documentation available: PHP Function Reference « WordPress Codex

songdogtech