I noticed that I can create a blank file in my WordPress theme,
and use a function I’ve created in functions.php without including anything.
How is this possible?
My function in functions.php (
function getContentFromID($int) {
$my_id = $int;
$my_id = get_post($my_id);
$content = $my_id->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
}
ONLY content in test.php (and it gets the correct content if i replace $scrapeID
with e.g. 135)
<?php getContentFromID($scrapeID); ?>
WordPress automatically include function.php in the template. see http://codex.wordpress.org/Theme_Development
By setting
auto_prepend_file
, it is possible to include a PHP file for every PHP file.Something else has already included functions.php before test.php has been included. PHP puts everything in a single global scope unless you tell it otherwise somehow.
Because your new file is included by some other file, and this file which includes your file also includes the functions file, so the functions are visible to your file.