WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to insert slider in header.php to appear only in the Home page (22 posts)

  1. adolfocc
    Member
    Posted 1 year ago #

    Hi everyone,

    I got this nice theme:

    http://www.elegantthemes.com/demo/?theme=Nimble

    and this slider:

    http://kreaturamedia.com/codecanyon/plugins/layerslider/

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

  2. Hristo SiteGround
    Member
    Posted 1 year ago #

    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; ?>
  3. adolfocc
    Member
    Posted 1 year ago #

    Hello,

    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!

  4. adolfocc
    Member
    Posted 1 year ago #

    Woww!

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

  5. Hristo SiteGround
    Member
    Posted 1 year ago #

    Hi,

    Great, I'm glad that this worked :)

  6. va.vishalarora02@gmail.com
    Member
    Posted 1 year ago #

    Thanks alot......Hristo SiteGround
    it worked for me.

  7. pezomatic
    Member
    Posted 1 year ago #

    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?

  8. Zulfikar Nore
    Member
    Posted 1 year ago #

    @pezomatic,

    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.

  9. Ursula (aka WP Gal)
    Member
    Posted 11 months ago #

    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!

  10. e-ditora
    Member
    Posted 11 months ago #

    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!

  11. WPyogi
    Volunteer Moderator
    Posted 11 months ago #

    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.

  12. e-ditora
    Member
    Posted 11 months ago #

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

  13. subhashsrs
    Member
    Posted 9 months ago #

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

    Regards
    Subhash

  14. casper14209
    Member
    Posted 8 months ago #

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

    See
    Function is_home()
    and
    Function is_front_page()

  15. Mo2web
    Member
    Posted 8 months ago #

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

  16. aniry1
    Member
    Posted 7 months ago #

    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.

  17. aniry1
    Member
    Posted 7 months ago #

    I am using childishly simple theme.

  18. Mo2web
    Member
    Posted 7 months ago #

    Hi,

    Put this code in your header.php but replace the middle line with the metaslider php code given to you (you can find it at the bottom right corner of the meta slider page).

    <?php if ( is_home() ):?>
    <?php echo do_shortcode("[metaslider id=1]"); ?>
    <?php endif; ?>

    Hope that helps

  19. Mo2web
    Member
    Posted 7 months ago #

    Sorry, not sure about your particular theme..

  20. tonyreyes
    Member
    Posted 5 months ago #

    http://www.candlelighterssoco.com

    I want to change the purple heading in my page and replace it with a picture, i just don't see where to do it, can anyone help!! is a wordpress theme from theme forest is the Wisdom theme, thank you

  21. casper14209
    Member
    Posted 5 months ago #

    @tonyreyes
    This doesn't quite apply to this thread, but your request is quite easy if you use inspect element.
    I recommend using Google Chrome.
    You'll see that this is done in your style sheet on line 38 for the global image part

    span.grung {
    width: 100%;
    height: 176px;
    float: left;
    background-image: url(images/cloud.png);
    background-repeat: no-repeat;
    background-position: top center;
    position: absolute;
    z-index: 1;
    }

    The white highlights are also done in your stylesheet on line 195.

    #outer_wrapper {
    width: 100%;
    background: url(images/layers.png) no-repeat top center;
    position: relative;
    z-index: 2;
    }

    And the actual color part appears (hopefully) to be being pulled from a setting in the theme options because it is in the page at line 20.

    .backcolr, .sub-menu, span.current {
    background-color: #8200ad !important;
    }
  22. matzone
    Member
    Posted 4 months ago #

    @casper14209 ... thanks for the 'is_front_page()'

Topic Closed

This topic has been closed to new replies.

About this Topic