0

If I wanted to show a slider on the home page only, is it better or does it make a difference if I:

  • use a PHP if/then statement and echo a division and markup, or
  • use CSS along with a body class and display none the division? or
  • a combination of both

What's the best practice?

  • Conditional Tags is Good Option – Mohit Bumb Oct 3 '11 at 13:09
1

target homepage only with if statement.

if ( is_front_page() or is_home() )

}

if your home page has page/2 page/3 then use the following to display the slider on only page 1 of the homepage.

if ( is_front_page() or is_home() && ! is_paged() ) {

}
  • Important to note, that I used or for a reason. It's more lightweight than || and && so the first one will be checked first and than compared to the result or ! is_paged(). – kaiser Aug 30 '12 at 12:51
0
if ( is_front_page() or is_home() )
{
    // Your Slider Code
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.