Support » Themes and Templates » How to insert slider in header.php to appear only in the Home page

  • Resolved adolfocc


    Hi everyone,

    I got this nice theme:

    and this slider:

    and I’d like to insert the slider inside the header (instead of the default slider) in the home page, so, my only idea (wrong one) was to use an exclusive page (Full wide page) to my Home and to create a new header.php with a different name and the php code of this slider inside and then, to call it from the fullwidepage.php with the editor instead of the original header.php.

    In this way I got just an error in the php code.

    If I insert the slider php code in the normal header.php it works but I don’t want to show it in all pages of my menu. And if I use the shortcode in the container of the Home page editor, of course it doesn’t appear in the place of the original slider.

    I think maybe it’s so simple but my skills with WordPress are almost beginner.. that could be nice if someone share any idea with me,

    Thanks in advance! )

Viewing 15 replies - 1 through 15 (of 21 total)
  • Hello,

    If you want to display the slider only on the front page of your site, you can use this code:

    <?php if ( is_home() ):?>
    Your Slider HTML goes here
    <?php endif; ?>


    Thank you for your answer, that look very easy but I don’t get it..
    I got two kind of shortcodes from the slider, one to insert in the page/post editor:

    [layerslider id=”1″]

    and other to insert for php content:

    <?php echo do_shortcode(‘[layerslider id=”1″]’); ?>

    So, I tried to insert it inside your code in the header.php:

    <?php if ( is_home() ):?>
    <?php echo do_shortcode(‘[layerslider id=”1″]’); ?>
    <?php endif; ?>

    But it doesn’t work, I think, because that is not HTML code.. anyway, I can see other code around similar to my code and with the function: if ( is_home() ), so I tried with:

    <?php if ( is_home() ) echo do_shortcode(‘[layerslider id=”1″]’); ?>

    but nothing happens.. Im looking for more info about if ( is_home() ) but actually I don’t understand so much.. could you show me the light??

    : ) thanks!


    I get it! hihi a few googles more and I found it:

    <?php if ( is_page( ‘home’ )) echo do_shortcode(‘[layerslider id=”1″]’); ?>

    Thank you any way! )


    Great, I’m glad that this worked 🙂

    Thanks alot……Hristo SiteGround
    it worked for me.

    I am trying to do something similar. I am using a theme that does not have a slider. I want to use LayerSlider to make a full-width slider at the top of my page. I can easily insert a LayerSlider into a page by simply inserting a shortcode for it, but how can I get it to display at the very top of my pages (above all the content that the theme is generating)?

    I am a newbie, so can you please explain exactly where in the code I need to insert the LayerSlider code so it does not mess my theme up?


    You need to start your own thread as this one is already marked as resolved!

    In addition you need to state what theme you are using plus what instructions does the plugin come with in terms of using template tags as opposed to using the shortcode.

    adolfocc, thank you for posting this question! I’m actually looking to use the same theme for a client, and was trying to figure out how to replace the slider with something different. I think your solution might help me, and I just wanted you to know that I appreciate the fact that you came back to post your solution!

    Take care!

    Please can anybody tell me WHERE The CONDITION IF php code, shared by Hristo SiteGround, must be pasted?? Couple posts like this one was closed before indicate wich script we use to this code. Is it in Header.php in the same place I pasted my HTML slider code? Or is it a function.php code?

    I have a VSlider running in ALL my web site pages (TWENTY TWELVE template) and I need to display it at homepage only. Someone can help me, please?

    Thanks a lot!



    Forum Moderator

    If you start your own thread, someone can help you, but you must have a child theme set up to do what you are asking about.

    I’m sure I don’t need a child theme to this. I guess only know WHERE this condition must be palced… Ok, let’s open up my own thread, thanks…

    Hi, Please open the Layer slider, you want to insert, Then Click on “Help” Button, at the top of page. There code will be appear.

    As I have opened by First LAyer Slider, the clicked on ” Help” Following codes are appearing:

    <?php layerslider(1); ?> // Displays the first slider on every page
    <?php layerslider(1, ‘homepage’); ?> // Displays the first slider only on your home page
    <?php layerslider(1, ‘my-custom-post-title’); ?> // Displays the first slider on a custom page by name
    <?php layerslider(2, ‘1369’); ?> // Diplays the second slider on a custom page by ID
    <?php layerslider(3, ‘homepage,about-us,1234’); ?> // Displays the third slider on multiple pages””




    Just to clarify Hristo SiteGround’s code

    <?php if ( is_home() ):?>
    Your Slider HTML goes here
    <?php endif; ?>

    Is for the is_home() function and this only works for your “posts page”.
    Note: WordPress 2.1 handles this function differently than prior versions
    If you are using a static home page you’ll want to use

    <?php if(is_front_page()):?>
      Embed slider here
    <?php endif;?>

    Function is_home()
    Function is_front_page()



    Thank you everyone for posting your solutions, it has been very helpful!

    One thing I still don’t get, how do I ensure that the slider is full width (and adjusts to full screen in different screen sizes) as in the Nimble theme demo. I used the:

    <?php if ( is_home() ):?>
    Your Slider HTML goes here
    <?php endif; ?>

    in my header.php but my slider is not full width. Can anyone please help??

    (I tried opening my own thread but no one replied…)

    Hi,I want to replace the banner image with metaslider, only in home page. I tried to introduce this cod: <?php echo do_shortcode(“[metaslider id=155]”); ?> in header.php in different places, but it appeared on top of banner, or under it. but I need to replace the image with the slider only in home page. Please help me.

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘How to insert slider in header.php to appear only in the Home page’ is closed to new replies.