Just follow the code :).
Before calling wp()
, /wp-blog-header.php
loads /wp-load.php
(which assuming you have correctly installed WordPress) loads /wp-config.php
. At the bottom of that file, it calls /wp-settings.php
.
This file loads a lot of other files, initialising the core parts of WordPress. Amongst them, is the wp-includes/functions.php
file. It’s inside this file that wp()
is defined.
Once /wp-settings.php
has finished loading all the files, wp()
is then called – this ‘starts’ WordPress (interpreting the incoming url, processing it into a query, choosing a template and finally outputting the content and sending into the user.