
🖥 How to show content only on the WordPress front page
You open the WordPress admin panel and realize: the promo banner belongs on the homepage, but on individual posts it looks intrusive. Or a subscription widget that collects emails on the homepage simply takes up space in the article body. Sound familiar?
WordPress does not offer a built-in "show only on homepage" toggle, but the task is solved easily with two lines of PHP. No plugins, no guesswork hacks in functions.php. Below are three proven methods, from conditional tags to theme templates, with clear code examples and an explanation of the difference between is_front_page() and is_home().
💡 Quick overview:
- Use is_front_page() in your theme's header.php or footer.php
- Understand the difference between is_front_page and is_home
- To replace entire blocks, create separate template files
- No plugins required
What are WordPress conditional tags
Conditional tags are built-in WordPress PHP functions that check conditions and return true or false. They work as a fork: "if the page is the homepage, show the banner; otherwise, do nothing."
WordPress core contains dozens of such functions: is_single() for individual posts, is_page() for pages, is_category() for categories, is_404() for nonexistent addresses, is_search() for the search page, and others. They let you precisely control content output without editing each template manually; the check fires on the fly when the page loads.
For the "homepage only" task, two tags matter most: is_front_page() and is_home(). They look similar but behave differently depending on reading settings, and confusion between them has cost beginners many hours of debugging.
Method 1: is_front_page(), the primary tool
is_front_page() returns true when a visitor is on the site's front page, the one that opens at the root URL (https://yoursite.com/). This is your main tool for the vast majority of homepage-only content tasks.
Basic syntax:
1 <?php if ( is_front_page() ) : ?> 2 <div class="homepage-banner"> 3 <p>Специальное предложение только для посетителей сайта!</p> 4 </div> 5 <?php endif; ?> 6
Place this code in header.php (right after the opening <body> tag) or in footer.php; the banner will appear exclusively on the homepage and will be absent on all other pages.
Example outputting a custom HTML block:
1 <?php if ( is_front_page() ) : ?> 2 <section class="hero-promo"> 3 <h2>Бесплатная консультация</h2> 4 <p>Оставьте заявку — и мы перезвоним в течение 15 минут.</p> 5 </section> 6 <?php endif; ?> 7
The same approach works for ad scripts, custom styles, or a separate shortcode: wrap the desired block in if ( is_front_page() ), and it loads only where needed.
Important nuance: the function must be called after WordPress has completed the main database query. Do not place it in functions.php outside hooks; before the wp action fires, it will return false. Safe placement: inside theme files such as header.php, footer.php, sidebar.php, and front-page.php. Alternatively, use hooks: wp, template_redirect, or wp_head.
Method 2: is_home(), for the blog page
is_home() returns true when a visitor is on the page that displays the latest blog posts. And here lies a trap that catches almost every beginner.
The code looks just as simple:
1 <?php if ( is_home() ) : ?> 2 <p>Подпишитесь на нашу рассылку — новые статьи каждую неделю.</p> 3 <?php endif; ?>
The difference is in the settings. Go to the admin panel: Settings → Reading → Your homepage displays. If "Your latest posts" is selected, then is_front_page() and is_home() work identically: both return true on the homepage. But if "A static page" is selected, then:
is_front_page()→trueon the static page you designated as the homepageis_home()→trueon the page you designated for displaying posts (even if it is physically located at/blog/)
In other words: is_home() is tied to the blog page, not to the site's front page. If you have a static landing site and the blog is at /blog/, then is_home() on the homepage (/) will return false.
is_front_page() vs is_home(): comparison table
Scenario | Reading settings | is_front_page() | is_home() |
|---|---|---|---|
Homepage = latest posts | "Your latest posts" |
|
|
Homepage = static page (visitor at | Static page + separate blog page |
|
|
Blog page = | Static page + separate blog page |
|
|
Any other page or post | Any settings |
|
|
The rule is simple: if you need content strictly on the homepage, use is_front_page(). If you need content on the page with the post feed (regardless of whether it is the homepage), use is_home().
In practice, most tasks are solved with is_front_page(). is_home() comes in handy when the blog is on a separate page and you want, for example, to show a "Popular posts" widget specifically there but not on the landing homepage.
Method 3: separate template files
When you need to replace not a line or two but an entire structural block (a sidebar, footer, or header), wrapping each element in if becomes cumbersome. WordPress supports a mechanism for specific template files: you create a file for a particular page, and the core picks it up automatically.
Step 1. Create a new file. In your theme folder, create one of three variants:
sidebar-home.php, a sidebar for the homepagefooter-home.php, a footer for the homepageheader-home.php, a header for the homepage
Step 2. Fill it with content. Place the HTML and PHP that should appear only on the homepage in the file. For example, sidebar-home.php:
1 <div class="homepage-sidebar"> 2 <h3>О нашем проекте</h3> 3 <p>Мы помогаем малому бизнесу запускать сайты на WordPress с 2018 года.</p> 4 5 <h3>Подписка</h3> 6 <?php echo do_shortcode( '[newsletter_form]' ); ?> 7 </div> 8
Step 3. Call the file in the template. In front-page.php or index.php (depending on your theme), replace the standard call:
1 <?php get_sidebar( 'home' ); ?> 2 <?php get_footer( 'home' ); ?> 3 <?php get_header( 'home' ); ?>
WordPress uses the 'home' argument to automatically substitute the files sidebar-home.php, footer-home.php, and header-home.php respectively. If a file is not found, it falls back to the standard sidebar.php.
When this method is justified. Choose the template approach if:
- The entire block is changing (not a single button, but the whole sidebar structure)
- The theme already uses
front-page.phpand the logic does not mix - You plan to maintain the site long-term and want clean file organization
For small edits the method is overkill; the is_front_page() conditional tag is sufficient.
Possible errors and how to avoid them
Calling before query initialization. The most common issue: is_front_page() in functions.php without a hook. The function silently returns false, and you assume the code is broken. Solution: always wrap the check in a wp or template_redirect hook:
1 add_action( 'wp', 'my_homepage_content' ); 2 function my_homepage_content() { 3 if ( is_front_page() ) { 4 add_action( 'wp_head', 'my_homepage_banner' ); 5 } 6 }
Confusion with reading settings. If you switched the site from a static homepage to the latest posts feed and forgot about it, is_home() suddenly fires where it should not. Check Settings → Reading first.
Hard-coding the page ID. Some developers check if ( get_the_ID() == 5 ) instead of is_front_page(). This is fragile: change the homepage in settings, and everything breaks. Use conditional tags; they track settings automatically.
The topic of WordPress conditional tags is covered more deeply in this video, from is_page() to custom conditions for non-standard templates. If you work with themes regularly, 15 minutes of viewing will save hours of debugging in the future.
⁉️🤔 Frequently asked questions
What to choose: is_front_page() or is_home()?
In most cases,
is_front_page(). It returnstrueon the site's front page regardless of whether it is a static page or the posts feed. Useis_home()only when you specifically need the blog page (for example,/blog/), not the homepage.
Can both tags be used simultaneously?
Yes, the construct
if ( is_home() && ! is_front_page() )returnstrueonly on the blog page when it is not the homepage. Useful for sites with a static homepage and a separate posts section.
Does is_front_page() work with caching plugins?
Yes, but with a caveat. Conditional tags fire on the server side before HTML delivery; cache plugins (WP Rocket, W3 Total Cache) do not affect this. However, with ESI blocks (Edge Side Includes), verify that your cache plugin supports them.
How do I display different content on the homepage for logged-in and logged-out users?
Combine
is_front_page()withis_user_logged_in(). For logged-in users, a personal greeting; for guests, a sign-up call to action. The code takes five lines and goes inheader.php:
1 <?php if ( is_front_page() && is_user_logged_in() ) : ?> 2 <p>С возвращением! Вот ваши последние заказы.</p> 3 <?php elseif ( is_front_page() ) : ?> 4 <p>Добро пожаловать! Зарегистрируйтесь для персональных скидок.</p> 5 <?php endif; ?>
Does a child theme need its own header-home.php files?
If the parent theme already contains
header-home.php, the child theme automatically inherits it. To override, create a file with the same name in the child theme folder. WordPress searches for the template in the child theme first and only then in the parent.
What to use in 2026: a conditional tag or a separate file?
The choice comes down to the scope of the task. Remember a simple rule: one line of code or one HTML block, use is_front_page(). If an entire structural block (sidebar, footer, header) with its own markup and logic is changing, create separate template files.
In practice, most homepage-only content tasks are handled with two lines of a conditional tag. It is fast, does not spawn extra files in the theme, and reads easily when maintaining the site six months later: you do not have to guess why you created sidebar-home.php because you see the explicit check right in the template.
Try it right now: open your active theme's header.php, find the spot after <body>, and add a test block with is_front_page(). If everything works, you have mastered WordPress conditional tags in five minutes.



