Skip to content

fix(search): remove duplicate search form on no-results page#2712

Open
faisalahammad wants to merge 1 commit into
Automattic:trunkfrom
faisalahammad:fix/1796-remove-duplicate-search-form
Open

fix(search): remove duplicate search form on no-results page#2712
faisalahammad wants to merge 1 commit into
Automattic:trunkfrom
faisalahammad:fix/1796-remove-duplicate-search-form

Conversation

@faisalahammad

@faisalahammad faisalahammad commented May 15, 2026

Copy link
Copy Markdown
Contributor

Summary

When a search returns no results, the page renders two identical search forms — one in the page header (search.php:19) and another in the content area (content-none.php:39). Remove the duplicate from the content area since the header form is already visible.

Fixes #1796

Changes

newspack-theme/template-parts/content/content-none.php

Before:

elseif ( is_search() ) :
    ?>
    <p><?php esc_html_e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'newspack-theme' ); ?></p>
    <?php
    get_search_form();

else :

After:

elseif ( is_search() ) :
    ?>
    <p><?php esc_html_e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'newspack-theme' ); ?></p>
    <?php

else :

Why: The search results page already has a search form in its header. The else branch (used by 404 pages and empty archives) retains its search form since those pages don't have one elsewhere.

Testing

Test 1: Search with no results

  1. Search for a term that returns nothing (e.g., ?s=xyznonexistent123)
  2. Verify only one search form appears (in the page header)

Test 2: 404 page

  1. Visit a nonexistent URL
  2. Verify the search form still appears in the content area

Test 3: Empty archive

  1. Visit a category with no posts
  2. Verify the search form still appears in the content area

Screenshot

image

The search template (search.php) already renders a search form in the
page header. When no results are found, content-none.php was rendering
a second identical form via the is_search() branch. Remove the
duplicate while keeping the search form in the else branch (used by
404 pages and empty archives).

Fixes Automattic#1796
@faisalahammad faisalahammad requested a review from a team as a code owner May 15, 2026 16:48
@laurelfulford laurelfulford added the [Status] Needs Review The issue or pull request needs to be reviewed label May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Review The issue or pull request needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unnecessary duplicated search box on "No Results" page?

2 participants