我正在使用sage-Themes框架开发wordpress主题。我在函数中有这个数组。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
];
在下面加载
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);
现在我有了home\\u短代码。php和短代码。php,我想要home\\u短代码。php只能加载在我的首页/主页上,我如何才能做到这一点?
最合适的回答,由SO网友:Aniruddha Gawade 整理而成
您可以使用is_home()
或is_front_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
}