user3214264
user3214264

Reputation: 69

Wordpress - Check if page is the main page

How can I check if the page is a home page?

I have this pages, Home, News.
In Reading Settings I set:
Front page: - Home
Posts page: - News

When I check

var_dump(is_front_page());
var_dump(is_home());

Home Page and News Page has the same values

boolean false

boolean true

But I need to separate them and know the Front page.

Upvotes: 0

Views: 4774

Answers (4)

Mohamed Slimane
Mohamed Slimane

Reputation: 311

There is a difference between the index.php home page and the designated home page

So is necessary to definition it individually in both cases 'is_home or is_front_page' not 'is_front_page and is_front_page'

this can help you:

if(is_front_page() || is_home()){
    //do sothing
}

Upvotes: 1

Moeed Farooqui
Moeed Farooqui

Reputation: 3622

is_home()

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

make sure wp_reset_query(); is set before the conditional tag.

Why using wp_reset_query:

word press always keeps the original, unaltered query intact. So, to get back that where all the conditional tags works we have to use the wp_reset_query.

Upvotes: 0

Vikas Gautam
Vikas Gautam

Reputation: 978

if(is_front_page()({ echo do this } else { do this } 

Upvotes: 0

Ruben
Ruben

Reputation: 343

is_front_page() When the front of the site is displayed, whether it is posts or a Page. Returns true when the main blog page is being displayed and the 'Settings > Reading ->Front page displays' is set to "Your latest posts", or when 'Settings > Reading ->Front page displays' is set to "A static page" and the "Front Page" value is the current Page being displayed.

Upvotes: 0

Related Questions