• Kev5

    (@kev5)


    I added a search function to my 404 page. However, no matter how much I’ve tried, I can’t find how to remove the “Type to search, then press Enter” placeholder text.

    How do you remove it?

    Regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Sean Davis

    (@sdavis2702)

    Hi there,

    You should be able to do this in a couple of different ways. First of all, your theme has the ability to include a template file that specifically creates the output of the site’s default search form. I wrote about it here: http://buildwpyourself.com/wordpress-search-form-template/

    If your theme does overwrite the default search form, you can override that template from a child theme and simply make an edit to the text.

    You could also use something like the Say What? plugin, assuming the placeholder text is translation-ready. https://wordpress.org/plugins/say-what/

    Once activated, you’d copy the exact placeholder text into the “Original string” field (this field is case-sensitive… copy the original text EXACTLY). The “Text domain” field would be whatever is specified by what is controlling your search form. So if your theme is in control, you’d use its text domain. You would leave the “Text context” field blank. And for the “Replacement string” field, add the new text you want to display as the placeholder.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    here’s the code to change the placeholder text:

    function tachp_search_form($html)
    {
        $html = str_replace('placeholder="Search ', 'placeholder="Search site for ', $html);
    
        return $html;
    }
    add_filter('get_search_form', 'tachp_search_form');

    You could set placeholder=”” to remove it.

    Thread Starter Kev5

    (@kev5)

    Hi sdavis. Thank you for the response. I already tried those things you mentioned (I even used your website 🙂 ), however, it didn’t work for some reason. Thanks for the suggestions anyway.

    Thread Starter Kev5

    (@kev5)

    Hi sterndata. Thank you for the response. I tried removing all the code between the double quotes, but it gives me an error. What part of the code do I need to change?

    Moderator cubecolour

    (@numeeja)

    What is the URL of your site?

    Which theme are you using?

    What code was added to the 404 template for the search?

    Thread Starter Kev5

    (@kev5)

    Hi cubecolour,

    http://www.pathtodiscipline.com/

    Headway Themes

    <?php get_search_form(); ?>

    Moderator cubecolour

    (@numeeja)

    How to create a customised version of the search form is outlined at the bottom of the page at https://developer.wordpress.org/reference/functions/get_search_form/

    If this does not work for you, the get_search_form() function may already have been changed by your theme in a searchform.php, but this can most likely be changed by creating a customised version of the theme’s searchform.php in your child theme if you are using one.

    I don’t know whether headway calls and customises the search form by the standard WordPress methods as it is a commercial theme so I don’t have sight of its code, and support for commercial themes cannot be provided on these forums. You should be able to get headway-specific support for this from the vendor of the theme.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Remove Placeholder Text From WordPress Search Function’ is closed to new replies.