Add another Search Form to a No Results Page in Genesis

The ‘no results page’ from a search in Genesis leaves the visitor with not much info to go on,  and if the no results page is a full width page with no sidebar which had contained the search widget it would be nice to have the option to quickly search again.

genesis-no-results
Genesis no results page

Make a Child Theme Search Template

You can copy the search.php template from the Genesis framework into your child theme and then that template will be used to control the display and output.

To change the text for Search Results for:

Change the relevant text in the highlighted line below..

<?php
/**
* Genesis Framework.
*
* WARNING: This file is part of the core Genesis Framework. DO NOT edit this file under any circumstances.
* Please do all modifications in the form of a child theme.
*
* @package Genesis\Templates
* @author StudioPress
* @license GPL-2.0+
* @link http://my.studiopress.com/themes/genesis/
*/
add_action( 'genesis_before_loop', 'genesis_do_search_title' );
/**
* Echo the title with the search term.
*
* @since 1.9.0
*/
function genesis_do_search_title() {
$title = sprintf( '<div class="archive-description"><h1 class="archive-title">%s %s</h1></div>', apply_filters( 'genesis_search_title_text', __( 'Search Results for:', 'genesis' ) ), get_search_query() );
echo apply_filters( 'genesis_search_title_output', $title ) . "\n";
}
genesis();
view raw no-results.php hosted with ❤ by GitHub

To change the text further down “Sorry, no content matched your criteria.” and add another search box you can remove the default action that occurs when no results are found and add your own custom action – that action is the genesis_do_noposts

<?php
/**
* Genesis Framework.
*
* WARNING: This file is part of the core Genesis Framework. DO NOT edit this file under any circumstances.
* Please do all modifications in the form of a child theme.
*
* @package Genesis\Templates
* @author StudioPress
* @license GPL-2.0+
* @link http://my.studiopress.com/themes/genesis/
*/
add_action( 'genesis_before_loop', 'genesis_do_search_title' );
/**
* Echo the title with the search term.
*
* @since 1.9.0
*/
function genesis_do_search_title() {
$title = sprintf( '<div class="archive-description"><h1 class="archive-title">%s %s</h1></div>', apply_filters( 'genesis_search_title_text', __( 'Search Results for:', 'genesis' ) ), get_search_query() );
echo apply_filters( 'genesis_search_title_output', $title ) . "\n";
}
remove_action( 'genesis_loop_else', 'genesis_do_noposts' );
add_action( 'genesis_loop_else', 'themeprefix_genesis_do_noposts' );
function themeprefix_genesis_do_noposts() {
printf( '<div class="entry"><p>%s</p></div>', apply_filters( 'genesis_noposts_text', __( 'Sorry, no results matched your search, try again below.', 'genesis' ) ) );
echo '<div class="wrap search-again"><h3>Search Again</h3>';
get_search_form();
echo '</div>';
}
genesis();

So above I am removing the the genesis_do_noposts and adding my own, my own has custom wording and also a includes another search form get_search_form(); – you can add anthing else which may work well in this area to keep the user engaged in the site.

Add in some CSS to finish it off.

genesis-search-again

3 comments

Leave your comment