1

I'm re-developing a wordpress theme using sage them framework. I have this array in functions.php

$sage_includes = [
  'lib/assets.php',    // Scripts and stylesheets
  'lib/theme_options.php',    // Theme Options
  'lib/setup.php',     // Theme setup
  'lib/titles.php',    // Page titles
  'lib/wrapper.php',   // Theme wrapper class
  'lib/home_shortcodes.php', // Homeapage Shortcodes
  'lib/shortcodes.php' // Old Theme Shortcodes

];

which is loaded below

foreach ($sage_includes as $file) {
  if (!$filepath = locate_template($file)) {
    trigger_error(sprintf(__('Error locating %s for inclusion', 'sage'), $file), E_USER_ERROR);
  }

  require_once $filepath;
}
unset($file, $filepath);

Now I have home_shortcodes.php and shortcodes.php, I want the home_shortcodes.php to be loaded only on my front page / homepage how can I achieve something like that?

3

You can use is_home() or is_front_page() to check the current page.

$sage_includes = [
    'lib/assets.php',    // Scripts and stylesheets
    'lib/theme_options.php',    // Theme Options
    'lib/setup.php',     // Theme setup
    'lib/titles.php',    // Page titles
    'lib/wrapper.php',   // Theme wrapper class
    'lib/shortcodes.php' // Old Theme Shortcodes

];
if(is_home() || is_front_page()){
    $sage_includes[] = 'lib/home_shortcodes.php'; // Homeapage Shortcodes
}
| improve this answer | |

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.