apply_filters( 'relevanssi_search_form', string $form )

This filter hook filters the HTML code for Relevanssi-generated search forms.


(string) The search form HTML code.

More information

Relevanssi has a shortcode you can use to create search forms on your site. See the shortcode documentation.

The shortcode gets the basic search form from the function get_search_form(), which gets it from the theme searchform.php file or the default WordPress search form. Relevanssi adds extra fields to the form, depending on the shortcode settings. Then Relevanssi returns the search form through this filter hook.

This hook gets the complete search form HTML code so that you can make changes to the form. Another method of modifying the search form is modifying the searchform.php file in your theme.

You can also use the get_search_form filter hook. That filter hook is the same as this filter hook but applies to all search forms. Also, this filter hook runs after Relevanssi adds the new fields, while get_search_form happens before that.

For example, if you want to add a post type dropdown in the search form but want to exclude the “archive” post type from the form, you can add this to your site:

add_filter( 'relevanssi_search_form', function( $form ) {
  $form = str_replace( '<option value="archive">Archive</option>', '', $form );
  return $form;
} );