Thursday, April 18, 2013

Only show div on homepage/blog index in wordpress/php

The following example can be used in your sidebar to display different content when displaying home page. 

<?phpif ( is_home() ) {
    
// This is a homepage} else {
    
// This is not a homepage}?>


 ------------------------
Also here is an other code.

<?php if(is_home()): ?>

<div>Your div.</div>

<?php endif; ?>
Using above code works fine as long as you are not setting static Page for the Front Page display from here Administration > Settings > Reading.
<?php if(is_front_page()): ?>

<div>Your div.</div>

<?php endif; ?>
But this code will work irrespective of whether the main blog page is showing or you have set a static page to show on home page.

1 comment:

  1. I read your whole blog. Your work is really good and inseparable .Thanks for sharing.
    Wordpress Development

    ReplyDelete