I have a custom themed site which is not using the correct page template to display search results.
I inherited the site with the theme and I'm now trying to make some changes; I did not create the theme and I cannot reach the person who did, so I'm on my own.
The theme contains
search.php files but when the search results are displayed it is using the
page.php template instead. I know this because I placed HTML comments in all the template files to show the file name and I'm seeing
<!-- TEMPLATE: page.php --> when I inspect the HTML in the browser.
<form method="get" id="searchform" action="<?php echo esc_url( home_url( ) ); ?>"> <label for="s" class="assistive-text"><?php _e( 'Search' ); ?></label> <input type="text" class="field" name='s' value="Search" id="s" placeholder="<?php esc_attr_e( 'enter search term' ); ?>" /> <input type="submit" class="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search' ); ?>" /> </form>
Common problems I've seen from other people's questions are the form
action URL not sending the search terms to the "home" page, and the search text box
name being changed from
s to something else, but none of these have been changed in my case. As far as I can see all the settings for the form are correct.
When submitted the search form results in the following URL:
which via the template hierarchy should use
search.php and if that is not available, use
index.php. But on my site
page.php is used, which is not even on the same "path" as the other search result template options as shown in the Wordpress template hierarchy diagram.
I have also seen questions about changing the default template using in a theme for certain pages, with the use of rewrite functions and the like. I cannot find anything of that sort in the
functions.php file of the theme; in fact there are no filters installed at all.
The normal methods of debugging problems are to switch to one of the default themes and see if things work but I cannot use that in this case; I am getting the correct search results, just not displayed in the correct page template (theme specific problem).
The other usual thing to do is to disable all plug-ins but I don't see how I can do that on a live site without visitors seeing a "messed up" site while I'm testing; and although we're not massively popular I don't want to disrupt any of the 500 or so visitors we get a day: unless there's a way I can do this sort of testing without causing problems?
So I need help in working out why the wrong template is being used, what else could cause the site to select a different template?