Wordpressing
Wordpressing

Reputation: 279

How does WordPress makes its functions available to theme files without an include or require statement

As we all know WordPress makes it's API functions such as

get_header();
get_sidebar();
get_footer();

and others as you may define in your own functions.php file available anywhere in your theme files.

How do you create similar functionality as this in your own external PHP applications/scripts without having to write an include or require statement at the top of every PHP file to access your own functions?

WordPress makes it's API functions and those defined in your themes functions.php file constantly available to you, so you can happily theme away without having to include multiple files each time.

I understand that the magic starts with WordPress' index.php which then includes wp-blog-header.php and then wp-load.php and a bunch of require/include statements are made at this point which setup the environment and make such functions available to us...

But I'm having trouble understanding how WordPress serves you the theme files whilst all the time throwing you back through it's original loop process of wp-blog-header.php and so forth to ensure those functions are made available to you...

I hope this makes sense!

Regards WP

Upvotes: 1

Views: 340

Answers (1)

xofer
xofer

Reputation: 1030

The theme files are included, by the process you describe (index.php, etc.), after the files that contain those function definitions.

Upvotes: 1

Related Questions