Use of PHP functions used to retrieve search forms in WordPress

Source: Internet
Author: User
Tags search form html
This article describes how to parse the PHP functions used to obtain search forms in WordPress, that is, the basic usage of the get_search_form function, for more information, see get_search_form. in WordPress, the get_search_form function is used to extract preset search forms or default search forms. Because the official function does not have any Chinese characters, I simply wrote it.

Description
The get_search_form function is used in WordPress to extract custom search forms or default search forms.
Whether the custom form or default form is displayed depends on whether the search. php file exists in your topic,
If the file exists, the file is called Automatically. if the file does not exist, the default search form is displayed.

Use

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

Parameters
$ Echo Boolean type, used to select whether to display or return variables.
Default value: true

Instance
The complexity is not as simple as you think.

<?php  get_search_form(); ?>

If you need to integrate Google custom search,
You just need to put some custom code in your search. php file. of course you need to set the style.

Function Source code

<?php /** * Display search form. * * Will first 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 * will be displayed. The default search form is HTML, which will 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 an action that is called whenever the function is run called, * 'get_search_form'. This can be useful for outputting JavaScript that the * search relies on or various formatting that applies to the beginning of the * search. To give a few examples of what it can be used for. * * @since 2.7.0 * @param boolean $echo Default to echo and not 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 = '';  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.