is_front_page() not working wordpress
is_front_page() not working wordpress
我正试图从"functions.php"加载脚本,就在我在首页的时候。
我在阅读选项中设置了一个名为home的静态页面。
首页正确加载了"front-page.php"模板,但是条件脚本加载不起作用。
这是我在"functions.php"文件中的内容:
wp_register_script('nivoslider', get_bloginfo('template_url').'/js/libs/nivoslider.js', false, false, true);
if (is_front_page()) {
wp_enqueue_script('nivoslider');
}
为什么没有按预期加载?这里发生了什么?
$isfrontpage = false;
if( is_front_page() || is_home() ) {
$isfrontpage = true;
} else {
$current = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$site = get_site_url();
$site = str_replace('http://', '', $site);
$site = str_replace('https://', '', $site);
$site = str_replace('www', '', $site);
if( $site == $current || $site . '/' == $current ){
$isfrontpage = true
}
}
来自法典-
当显示主博客页面时返回TRUE设置->阅读->首页显示设置为"你的最新帖子",或者当设置为"静态页面"且"首页"值为时当前页面正在显示
仅仅设置它使用你的首页模板并不能使它成为首页。当上述任何一个条件为真时,它就是头版。因此,对于您创建的这个页面,这两个值都必须为false。
另外,这只是包含内联与函数。php或你实际上钩到头部?
is_front_page();
在functions.php中无法正常工作,因为functions.php在能够检测到"front_page.php"
以下是脚本排队的正确方法:
<?php
add_action( 'wp_enqueue_scripts', 'my_custom_enqueue_scripts', 5 );
function my_custom_enqueue_scripts(){
wp_register_script('nivoslider', get_bloginfo('template_url').'/js/libs/nivoslider.js', false, false, true);
if (is_front_page()) {
wp_enqueue_script('nivoslider');
}
}
?>
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Rxjs5, distinct() is not working
- createOscillator noteOn not working
- Javascript - .getHours() not working
- Javascript setTimeout not working | onkeydown
- MongoDB $pull not working
- Express router.use not working
- JSONP not working
- window.opener not working in chrome & IE
- Backbone + RequireJS: Collection.each() is not working