Support » Theme: Pictorico » Change Search Placeholder text

  • Resolved pannlann

    (@pannlann)


    Hi,

    I’d like to change a placeholder text of search field. Could anyone please give me a direction? I just created a child theme but I’m very new to customise wp theme so I’m not sure what to do next 🙁

    Regards,
    Pan

    • This topic was modified 2 years, 6 months ago by  pannlann.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello @pannlann, follow the given steps.
    1.Open your child theme’s functions.php file.
    2.Add the code given below in functions.php file of your child theme and save it.

    add_filter( ‘get_search_form’, ‘pictorico_custom_searchform’, 10 );

    function pictorico_custom_searchform( $form ) {

    $form = ‘<form role=”search” method=”get” class=”search-form” action=”‘ . esc_url( home_url( ‘/’ ) ) . ‘”>
    <label>
    <span class=”screen-reader-text”>’ . _x( ‘Search for:’, ‘label’ ) . ‘</span>
    <input type=”search” class=”search-field” placeholder=”Enter your search placeholder text” value=”‘ . get_search_query() . ‘” name=”s” />
    </label>
    <input type=”submit” class=”search-submit” value=”‘. esc_attr_x( ‘Search’, ‘submit button’ ) .'” />
    </form>’;
    return $form;
    }
    3.Notice that in the code above => placeholder=”Enter your search placeholder text”. Here “Enter your search placeholder text” is the new placeholder text of search field. You need to write your desired text here.
    Hope you solved your problem. Thankyou.

    Hi sujanarya,

    I tried your code but I think there was a bug 🙁

    Hi @pannlann,

    Another approach is to save a new file named searchform.php to your child theme’s directory. Any code that you add to this file will be used in place of the default search box.

    Add the following to the file:

    <form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
        <label>
            <span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ) ?></span>
            <input type="search" class="search-field"
                placeholder="<?php echo esc_attr_x( 'Example …', 'placeholder' ) ?>"
                value="<?php echo get_search_query() ?>" name="s"
                title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
        </label>
        <input type="submit" class="search-submit"
            value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>" />
    </form>

    The following part of the above code defines the placeholder text:

    placeholder="<?php echo esc_attr_x( 'Example …', 'placeholder' ) ?>"

    Change Example to the specific text you wish to use.

    Let us know how you get on with that!

    Awesome!! Thanks Siobhan. All sorted 🙂

    I’m glad to hear that! 🙂 You know where to find us if extra questions come up, too.

    thank U

    @ahmadianjalal: You’re welcome! Feel free to start a new thread if questions come up.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Change Search Placeholder text’ is closed to new replies.