Forums

[resolved] Check if page is the main page (static front page) (6 posts)

  1. Zyn
    Member
    Posted 4 years ago #

    Hi,

    I am creating a website using WordPress as CMS and I want a static front page. This front page has some features I don't want on regular pages and therefor I wonder how I can set up a PHP-query to check if the current page is the front page, and if so place some special code in there.

    Thank you in advance.

  2. mores
    Member
    Posted 4 years ago #

    In your index.php theme file use this

    <?php if (is_home()) { do something }?>

    to check.
    If you have a static front page set as "home", then you need to use

    <?php if (is_page('Home')) { do something } ?>

    (obviously insert the slug of the page you have set as "home")

  3. Zyn
    Member
    Posted 4 years ago #

    In my page.php file (the front page is a page after all) I tried using:

    <?php if ( is_home() ) { ?>
    html here... tadadum...
    <?php } ?>

    I also tried this in index.php but neither gave any result.

  4. mores
    Member
    Posted 4 years ago #

    even if the front page is actually a Page, it is still called from the index.php, I believe.
    Try the second code I gave you, since the "is_home" function will not work if your front page is a Page. then you need to ask if the current Page is the Page with the name "home", or whatever you call it.

  5. Zyn
    Member
    Posted 4 years ago #

    Thank you. Using that code in the page.php made everything work exactly as I wanted it to.

  6. ktsixit
    Member
    Posted 3 years ago #

    I'm using a static page as a frontpage but non of the two pieces of code you suggest is working.

    My frontpage's title is in greek, I don't know if this may be a problem, although I have changed the encoding of index.php file.

    Am I missing something?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.