admin管理员组文章数量:1130349
I'm trying to load a slider in my header, but only on the homepage.
I'm using The Ultralight template if that helps.
I'm trying to (in template-functions.php) do the following:
<?php if ( is_page( 'home' ) ) : ?>
dynamic_sidebar( 'Homepage Widget' );
<?php endif; ?>
But this doesn't work. Now from a quick google, it seems I need to enqueue the request, but when I try this, I get a syntax error:
<?php
add_action( 'wp', 'wpse47305_check_home' );
function wpse47305_check_home() {
if ( is_home() )
add_action( 'wp_enqueue_scripts', 'my_scripts' );
}
function my_scripts() {
dynamic_sidebar( 'Homepage Widget' );
}
?>
Edit: So this doesn't seemingly add my sidebar in where I was expecting it to load in. I presume i've misunderstood the concept here.
I'm trying to load a slider in my header, but only on the homepage.
I'm using The Ultralight template if that helps.
I'm trying to (in template-functions.php) do the following:
<?php if ( is_page( 'home' ) ) : ?>
dynamic_sidebar( 'Homepage Widget' );
<?php endif; ?>
But this doesn't work. Now from a quick google, it seems I need to enqueue the request, but when I try this, I get a syntax error:
<?php
add_action( 'wp', 'wpse47305_check_home' );
function wpse47305_check_home() {
if ( is_home() )
add_action( 'wp_enqueue_scripts', 'my_scripts' );
}
function my_scripts() {
dynamic_sidebar( 'Homepage Widget' );
}
?>
Edit: So this doesn't seemingly add my sidebar in where I was expecting it to load in. I presume i've misunderstood the concept here.
Share Improve this question edited Nov 19, 2018 at 10:17 Andrew Berry asked Nov 19, 2018 at 10:10 Andrew BerryAndrew Berry 991 bronze badge 3 |2 Answers
Reset to default 0I havent tested yet but try using this, $url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; if is same as "example"
Yes, as @Jacob Peattie mentioned, I had got myself confused. I needed to put this in my header.php rather than in the template-functions.php
I'm trying to load a slider in my header, but only on the homepage.
I'm using The Ultralight template if that helps.
I'm trying to (in template-functions.php) do the following:
<?php if ( is_page( 'home' ) ) : ?>
dynamic_sidebar( 'Homepage Widget' );
<?php endif; ?>
But this doesn't work. Now from a quick google, it seems I need to enqueue the request, but when I try this, I get a syntax error:
<?php
add_action( 'wp', 'wpse47305_check_home' );
function wpse47305_check_home() {
if ( is_home() )
add_action( 'wp_enqueue_scripts', 'my_scripts' );
}
function my_scripts() {
dynamic_sidebar( 'Homepage Widget' );
}
?>
Edit: So this doesn't seemingly add my sidebar in where I was expecting it to load in. I presume i've misunderstood the concept here.
I'm trying to load a slider in my header, but only on the homepage.
I'm using The Ultralight template if that helps.
I'm trying to (in template-functions.php) do the following:
<?php if ( is_page( 'home' ) ) : ?>
dynamic_sidebar( 'Homepage Widget' );
<?php endif; ?>
But this doesn't work. Now from a quick google, it seems I need to enqueue the request, but when I try this, I get a syntax error:
<?php
add_action( 'wp', 'wpse47305_check_home' );
function wpse47305_check_home() {
if ( is_home() )
add_action( 'wp_enqueue_scripts', 'my_scripts' );
}
function my_scripts() {
dynamic_sidebar( 'Homepage Widget' );
}
?>
Edit: So this doesn't seemingly add my sidebar in where I was expecting it to load in. I presume i've misunderstood the concept here.
Share Improve this question edited Nov 19, 2018 at 10:17 Andrew Berry asked Nov 19, 2018 at 10:10 Andrew BerryAndrew Berry 991 bronze badge 3-
1
if( is_home() || is_front_page() )might be helpful. Because by defaultis_home()detects the blog page. And I don't think, enqueuing is necessary here. If the problem is specific to the Ultralight theme, then I'm afraid, the question would be off-topic here. – Mayeenul Islam Commented Nov 19, 2018 at 10:34 -
2
You seem to be mixing up a few things.
dynamic_sidebar()goes into the template itself, wherever you want it to appear. If it's in the header, then that would be header.php (probably, it depends on the theme). But to use dynamic sidebar you first need to register it so that you can put widgets in it. Useregister_sidebar()to do that. See here for an example. I'm not sure what you're trying to do with scripts here. How are you trying to add this slider, is it a widget? – Jacob Peattie Commented Nov 19, 2018 at 10:35 - solve your problem ? – vikrant zilpe Commented Nov 19, 2018 at 13:14
2 Answers
Reset to default 0I havent tested yet but try using this, $url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; if is same as "example"
Yes, as @Jacob Peattie mentioned, I had got myself confused. I needed to put this in my header.php rather than in the template-functions.php
本文标签: widgetsCan39t use ishome in templatefunctionsphp
版权声明:本文标题:widgets - Can't use is_home in template-functions.php 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749166397a2326255.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


if( is_home() || is_front_page() )might be helpful. Because by defaultis_home()detects the blog page. And I don't think, enqueuing is necessary here. If the problem is specific to the Ultralight theme, then I'm afraid, the question would be off-topic here. – Mayeenul Islam Commented Nov 19, 2018 at 10:34dynamic_sidebar()goes into the template itself, wherever you want it to appear. If it's in the header, then that would be header.php (probably, it depends on the theme). But to use dynamic sidebar you first need to register it so that you can put widgets in it. Useregister_sidebar()to do that. See here for an example. I'm not sure what you're trying to do with scripts here. How are you trying to add this slider, is it a widget? – Jacob Peattie Commented Nov 19, 2018 at 10:35