The PHP function used to get the search form in WordPress uses analytic _php techniques

Source: Internet
Author: User
Tags search form html

The Get_search_form function is used in WordPress to extract a preset search form or a default search form. Because the official this function does not have Chinese, so I simply write a bit.

Describe
the Get_search_form function is used in WordPress to extract a custom search form or a default search form.
Whether you display a custom form or display a default form depends entirely on the search.php file in your topic.
If the file is present, the file is called automatically, and the default search form is displayed if no.

Use

<?php
  get_search_form ($echo = true) 
?>

Parameters
$echo Boolean to select whether to display or return a variable.
Default value: True

Instance
It's not as complicated as you think, but it's so simple.

<?php
  get_search_form (); 
? >

Here's a mention, if you need to integrate Google custom search those words,
You just have to put a custom part of your code in your search.php file, and of course you need to set the style.

Function source Code

<?php/** * Display search form. * 'll attempt to locate the searchform.php file in either the child or * the parent, then load it. If it doesn ' t exist, then the default search form * would be displayed.
 The default search form is HTML, which'll be displayed. * There is a filter applied to the search form HTML in order to edit or replace * it.
 The filter is ' get_search_form '. * * This function is primarily used by themes which want to hardcode the search * form into the sidebar and also by the
 Search Widget in WordPress. * There is also a action is called whenever the function is run called, * ' Get_search_form '. This can is useful for outputting JavaScript, the * search relies on or various formatting so applies to the Beginn ing of the * search.
 To give a few examples of what it can is used for.
 * * @since 2.7.0 * @param boolean $echo Default to Echo and don't return the form. */function Get_search_form ($echo = True) {do_action (' Get_seaRch_form ');
 $search _form_template = locate_template (' searchform.php ');
 if ('!= $search _form_template) {require ($search _form_template);
 Return $form = ' <form role= ' search ' method= ' get ' id= ' searchform ' action= '. Esc_url (Home_url ('/')). ' "> <div><label class=" Screen-reader-text "for=" S ">". __ (' Search for: '). ' </label> <input type= ' text ' value= '. Get_search_query (). ' "Name=" S "id=" s "/> <input type=" Submit "id=" Searchsubmit "value=".
 
 esc_attr__ (' Search '). '/> </div> </form> ';
 if ($echo) echo apply_filters (' Get_search_form ', $form);
else return apply_filters (' Get_search_form ', $form); }?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.