1

I have a wordpress install, with two sub folders "assets" and "functions" these folders contain important files for the wordpress theme.

What would be the best way to load these files I've tried something like this which live in a file called constants.php in my root directory

    define('CSS_DIR', get_stylesheet_directory() . '/');
    define('FUNCTIONS_DIR', get_stylesheet_directory() . '/');

then in my functions.php file i've got

require_once(FUNCTIONS_DIR . 'functions/news.php');

Hope this is clear what I'm trying to achieve.

updated with errors

I seem to be getting the following errors.

Warning: require_once(FUNCTIONS_DIR/functions/news.php): failed to open stream: No such file or directory in /home/foxyrent/public_html/wp-content/themes/foxyrental/functions.php on line 21

Fatal error: require_once(): Failed opening required 'FUNCTIONS_DIR/functions/news.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/foxyrent/public_html/wp-content/themes/foxyrental/functions.php on line 21
  • 1
    I've updated my question - it might make more sense now – dannyw24 Feb 13 '14 at 14:24
  • Removed this in an attempt to fix it. I should of updated that line. Result stayed the same :( – dannyw24 Feb 13 '14 at 14:53
1

I usually split my theme's functions into several files as well, and include those in my functions.php, like so:

// load helper functions
require_once get_stylesheet_directory().'/inc/helper-functions.php';

// load admin functions
if (is_admin())
    require_once get_stylesheet_directory().'/inc/admin-functions.php';

// load theme functions
require_once get_stylesheet_directory().'/inc/theme-functions.php';

// load post functions
require_once get_stylesheet_directory().'/inc/post-functions.php';

// load WooCommerce functions
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))))
    require_once get_stylesheet_directory().'/inc/woocommerce-functions.php';

Why isn't this working for you?

If you are talking about bulk including, you might have a look at glob and the like...

  • I've tried figuring out what was wrong with my code but had no luck - I was calling constants.php in functions.php. However I've reverted to your method which seems clean and easy and works for me. – dannyw24 Feb 13 '14 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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