The is_front_page() WordPress PHP function determines whether the query is for the front page of the site.
Usage
if (is_front_page()) { // Code to execute if on the front page }
Parameters
- None
More information
See WordPress Developer Resources: is_front_page()
Examples
Load a different header on the front page
if (is_front_page()) { get_header('front'); } else { get_header(); }
Set the page title depending on the front page
<title><?php bloginfo('name'); ?> » <?php is_front_page() ? bloginfo('description') : wp_title(''); ?></title>
Display content only on the front page
Add this code to your theme’s functions file:
add_action('loop_start', 'using_front_page_conditional_tag'); function using_front_page_conditional_tag() { if (is_front_page()) { echo '<h2>Only Displays On The Front Page</h2>'; } }
Check if a specific page is the current front page
function wpdocs_page_is_front_page(int $id) { if ('page' !== get_option('show_on_front')) { return false; } $front_id = (int)get_option('page_on_front'); return $front_id == $id; }
Using is_front_page() with an action hook
add_action('wp', 'check_front_page'); function check_front_page() { if (is_front_page()) { echo 'This is the front page'; } else { echo 'This is not the front page'; } }