user2710234
user2710234

Reputation: 3225

only display plugin if on homepage using wordpress

I have an image slider plugin and i use this in my PHP header (header.php) to display it only on the homepage

<?php putRevSlider("home", "homepage") ?>

I want to display spaces/line breaks above and below the slider but only if on the homepage. i tried doing:

<?php
if( is_home() ) : ?>
    <p>&nbsp;</p><p>&nbsp;</p>
    <?php putRevSlider("home", "homepage") ?>
    <p>&nbsp;</p>
<?php endif; ?>

but that does not display anything

Upvotes: 0

Views: 225

Answers (3)

Joe Buckle
Joe Buckle

Reputation: 871

If you have a custom home page, you can experience difficulties with is_home()

Try getting the post_id and matching it against the wp_option get_option('page_on_front')

<?php
global $post;
if( get_option( 'page_on_front' ) == $post->ID : ?>
    <p>&nbsp;</p><p>&nbsp;</p>
    <?php putRevSlider("home", "homepage") ?>
    <p>&nbsp;</p>
<?php endif; ?>

Upvotes: 0

Use is_front_page() instead of is_home() - this ensures you are on the actual 'front page' instead of the 'home page' (which defaults to the blog posts page, index.php).

Upvotes: 3

vico
vico

Reputation: 2142

Check if your Theme apply a class to the wrapper container and solve this via css ( usually a standard )

with the class .home tag

and add padding to

.home .slider_container { padding:20px 0 0 20px }

Upvotes: 1

Related Questions