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?

1 Answer 1

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
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.