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
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