wordpress function files, how to loop require_once? -
i trying loop through require_once statements in wordpress functions.php file this
// initial theme setup require_once locate_template('/inc/init.php'); // register widget areas require_once locate_template('/inc/sidebar.php'); ...
why following loop not working?
$theme_includes = array( '/inc/init.php', // initial theme setup '/inc/sidebar.php', // register widget areas '/inc/scripts.php', // register scripts , stylesheets '/inc/nav.php', // main navigation '/inc/cleanup.php', // cleanup '/inc/customizer.php', '/inc/template-tags.php', // custom template tags '/inc/extras.php', // no theme functions '/inc/analytics.php' // google analytics ); foreach ( $theme_includes $include ) { require_once locate_template( $include ); }
i no error message files not load
if check the wordpress codex of locate_template() find function takes 3 parameters:
locate_template( $template_names, $load, $require_once )
$template_names
: should array of files/templates search for$load
: boolean, if set true load file(s) when found$require_once
: boolean, if set true load file(s) using require_once php function
so in case can forget foreach , pass array first parameter , set other 2 params true:
$theme_includes = array( '/inc/init.php', // initial theme setup '/inc/sidebar.php', // register widget areas '/inc/scripts.php', // register scripts , stylesheets '/inc/nav.php', // main navigation '/inc/cleanup.php', // cleanup '/inc/customizer.php', '/inc/template-tags.php', // custom template tags '/inc/extras.php', // no theme functions '/inc/analytics.php' // google analytics ); locate_template( $theme_includes, true, true );
Comments
Post a Comment