Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

With a plugin, I have used require_once in the init.php of a plugin that I have made for my site to make functions available.

With a child theme, where should I put the calls to require_once? When I put them into the template file that uses it, it doesn't seem to work.

EDIT

I would have thought that this

locate_template('../../plugins/events-and-bookings/lib/class_eab_event_model.php', true, false);

Would be equivalent to this:

if (!function_exists('jupiter_init')) {
    function jupiter_init() {
        require_once('../../plugins/events-and-bookings/lib/class_eab_event_model.php');
    }
}

But the first code snipper isn't working (but the second one is). I am placing both in the functions.php file of my child theme right after the initial

share|improve this question

1 Answer 1

up vote 2 down vote accepted

When you create a theme, you can use functions.php file for all utilize functions. Also this is the best place for all your require_once calls.

One trick I would like to recommend for theme development approach:

Don't use direct require_one call to include your scripts. Instead of it, use locate_template function to load scripts. By using this function, all child themes will be able to override your scripts. So for instance, you have file called utilize.php, and it lies in inc folder of your theme, then instead of calling require_once 'inc/utilize.php';, call locate_template( 'inc/utilize.php', true, false );.

Now it will be possible to create inc/utilize.php file in a child theme and override parent file.

share|improve this answer
    
check out my update, I tried using require_once in my functions.php and it worked perfectly - when I put locate_template in the same spot, it didn't seem to work - –  William Mar 11 '13 at 16:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.