Support » Fixing WordPress » Display IF Homepage Only

  • Hi guys,

    There was a section on my homepage in the header.php where I wanted to add content from a page ID, it worked for me and looks like this.

    <?php
    $page_id = 1493;

    $page_data = get_page( $page_id );

    echo apply_filters(‘the_content’, $page_data->post_content);
    ?>

    Because this is in the header.php file it is displaying on every page, blog, posts etc when I only want it on the homepage.

    What code do I add to say IF Homepage to display Else don’t display the content????

Viewing 3 replies - 1 through 3 (of 3 total)
  • http://codex.wordpress.org/Conditional_Tags

    depending if you have a static front page or if the posts page is on te front, use either is_front_page() or is_home();

    example:

    <?php if( is_home() ) :
    $page_id = 1493;
    $page_data = get_page( $page_id );
    echo apply_filters('the_content', $page_data->post_content);
    endif; ?>
    Thread Starter sarahjanes88

    (@sarahjanes88)

    Hi alchymyth, thank you very much it is working now using the is_front_page() , I appreaciate the help!

    One more problem is the next line, where I want to display the DIV only if is_front_page() , It’s not working because I have a plugin to display also within the DIV. What is wrong with this code?

    <?php if(is_front_page()) :
    
    	<div class="featuredimg" style="bottom: 0px;">
    
    <?php if (function_exists('vslider')) { vslider('homeslide'); }?>
    
    	</div>							
    
    	endif; ?>

    you need to close the php tags when switching to html code, and open them again when going back to php code;

    <?php if(is_front_page()) : ?>
    
    	<div class="featuredimg" style="bottom: 0px;">
    
    <?php if (function_exists('vslider')) { vslider('homeslide'); }?>
    
    	</div>							
    
    <?php endif; ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display IF Homepage Only’ is closed to new replies.