How to target only the front page (not subsequent paginated pages) in theme/plugin?

I’d like to switch on the front page ONLY. Not subsequent paginated pages (like ?paged=2). I want to output certain output only on the “true” front page of the site.

I’ve tried:

<?php if (is_front_page() && get_query_var('paged', 1) == 1 || 0): ?>

but this only works if the paged variable is present (ex:

Solutions Collecting From Web of "How to target only the front page (not subsequent paginated pages) in theme/plugin?"

You have a misconception about is_front_page(). Lets look at the source:

public function is_front_page() {
    // most likely case
    if ( 'posts' == get_option( 'show_on_front') && $this->is_home() )
        return true;
    elseif ( 'page' == get_option( 'show_on_front') && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) )
        return true;
        return false;

So from the above, is_front_page() will return true on

  • The static front page (when reading setting is set as Front page) and every paged page of the static front page. /page/2/ etc will return true as it is just a paged page of the static front page

  • The homepage when the reading setting is set to Your latest posts, as well as every paged page of the post page.

is_front_page() will return false on:

  • The blogpage when a static front page is set and the posts page are set with Posts page. However, is_home() will return true here

  • Any other page that is not the homepage or static front page.

What you are thinking of is is_paged(). This conditional will return false on the first page of a paginated query, and will return true on other page of a paginated query.

With this in mind, you would probably need the following

if (    is_front_page() // Can change to is_home()
     && !is_paged() // Use the NOT operator to return true on page one, false after that
) {
    // Do what you need to do