• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Programming / searchform.php not working in WordPress 3.6

searchform.php not working in WordPress 3.6

Last updated on August 20, 2013 by Sal Ferrarello

This problem arises from a difference in how WordPress 3.5.2 and 3.6 handle the case where there is both a searchform.php template AND a filter on the hook get_search_form.

In WordPress 3.5.2 in the presence of a searchform.php template, any filters on the hook get_search_form were ignored. With the upgrade to 3.6, filters on get_search_form are now applied.

This change in behavior came about as a result of http://core.trac.wordpress.org/changeset/23666 with the removal of return; on line 158. To clarify, I don’t think this is necessarily a bad change but it is a change.

Unfortunately, I have a number of themes built on Genesis (which applies a filter to the hook get_search_form *), which had custom searchform.php templates. The way to avoid this issue is to avoid using searchform.php and instead create your custom search form using a filter on the hook get_search_form.  However, the following will work as a quick fix restoring the WordPress 3.5.2 behavior.

Add this code to functions.php in your theme

function search_form_no_filters() {
  // look for local searchform template
  $search_form_template = locate_template( 'searchform.php' );
  if ( '' !== $search_form_template ) {
    // searchform.php exists, remove all filters
    remove_all_filters('get_search_form');
  }
}
add_action('pre_get_search_form', 'search_form_no_filters');

* Note:

In Genesis, the filter on ‘get_search_form’ appears in genesis/lib/structure/search.php

add_filter( 'get_search_form', 'genesis_search_form' );
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit

Filed Under: Programming Tagged With: WordPress

Reader Interactions

Comments

  1. Emily Nathan says

    July 30, 2015 at 10:17 pm

    Cool, this works for me. Thanks Sal for such a great resource.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in