• Hi guys,

    I have a piece of code that I want to run only in the homepage of my blog. The blog is setted up to display the latest posts. My code:

    <?php if (is_home()) : ?>
    (code that displays only in the homepage goes here)
    <?php endif; ?>

    This doesn’t seem to work. I tried is_front_page() and nothing too. Any clues? BTW, this code is loaded in footer.php

    Thanks,

    Rod

Viewing 7 replies - 1 through 7 (of 7 total)
  • Bump

    I sometimes run into the same issue. is_home() just does not work even though I am loading the blog front page with index.php as a template file.

    I’m clueless… Anybody else?

    EDIT:

    I think I got it:

    There has to be a WP-loop present in the index.php template in order for is_home() to work correctly. At least that’s the case with me. I omit the standard loop because I use a heavily customized index.php.

    So make you’re own few lines of code to do the same.

    In index.php before get_header…

    <?php $myvar = 'home';?>

    Then in the header.php

    <?php if($myvar == 'home') { ?>
    some code
    <?php } else { ?>
    some other code
    <?php } ?>

    Very basic example, but very easy to do…

    This assumes you have other template files to handle other pages, such as categories etc…

    Still possible if you only use an index file, just requires a little more work…

    I’ve had this issue also and using is_page('your_home_slug') seems to work as a quick workaround.

    Put <?php wp_reset_query(); ?> before the conditional tag. Worked for me.

    I found this here: https://forums.digitalpoint.com/showpost.php?p=7646656&postcount=2

    @ajanini
    Thanks, that did just the trick ??

    Thanks ajanini, this trick works perfect.

    Worked for me too.

    I had five either query_posts or get_posts running on the home page. the Berita theme I’m using has a widgetized footer that lets you specify which footer content to display on the home footer and other content to display on the blog footer. I was only getting the blog footer because of the conditional tags in use in the footer.php file. Resetting the query with the wp_reset_query(), for whatever reason, restores the is_home() function after is was presumably interfered with after a custom query_post() call. I ran the reset query in the footer and everything works again.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘is_home() not working’ is closed to new replies.