Calling directories to load in wordpress

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

Read More
    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

Related posts

1 comment

  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…

Comments are closed.