phpwordpressbuttonreplace

Change <input type="submit"> to a <button> in a Wordpress search form


I am trying to change Wordpress search submit <input type="submit"> button to <button>. So I am trying to use str_replace(). Here is my code:

add_filter('get_search_form', 'my_search_form_text');
 
function my_search_form_text($text) {
     $text = str_replace(
        '<input type="submit" class="search-submit" value="Search">',
        '<button type="submit" class="search-submit btn btn-outline-primary"><i class="fas fa-search"></i></button>',
        $text
     );
     return $text;
}

But it doesn't work.


Solution

  • In your theme's folder searchform.php file is exists. If not copy from default theme to your theme.

    Here replace your <input> with <button>