* General template tags that can go anywhere in a template.
* Includes the header template for a theme or if a name is specified then a
* specialised header will be included.
* For the parameter, if the file is called "header-special.php" then specify
* @since 5.5.0 A return value was added.
* @since 5.5.0 The `$args` parameter was added.
* @param string $name The name of the specialised header.
* @param array $args Optional. Additional arguments passed to the header template.
* @return void|false Void on success, false if the template does not exist.
function get_header( $name = null, $args = array() ) {
* Fires before the header template file is loaded.
* @since 2.8.0 The `$name` parameter was added.
* @since 5.5.0 The `$args` parameter was added.
* @param string|null $name Name of the specific header file to use. Null for the default header.
* @param array $args Additional arguments passed to the header template.
do_action( 'get_header', $name, $args );
$templates[] = "header-{$name}.php";
$templates[] = 'header.php';
if ( ! locate_template( $templates, true, true, $args ) ) {
* Includes the footer template for a theme or if a name is specified then a
* specialised footer will be included.
* For the parameter, if the file is called "footer-special.php" then specify
* @since 5.5.0 A return value was added.
* @since 5.5.0 The `$args` parameter was added.
* @param string $name The name of the specialised footer.
* @param array $args Optional. Additional arguments passed to the footer template.
* @return void|false Void on success, false if the template does not exist.
function get_footer( $name = null, $args = array() ) {
* Fires before the footer template file is loaded.
* @since 2.8.0 The `$name` parameter was added.
* @since 5.5.0 The `$args` parameter was added.
* @param string|null $name Name of the specific footer file to use. Null for the default footer.
* @param array $args Additional arguments passed to the footer template.
do_action( 'get_footer', $name, $args );
$templates[] = "footer-{$name}.php";
$templates[] = 'footer.php';
if ( ! locate_template( $templates, true, true, $args ) ) {
* Includes the sidebar template for a theme or if a name is specified then a
* specialised sidebar will be included.
* For the parameter, if the file is called "sidebar-special.php" then specify
* @since 5.5.0 A return value was added.
* @since 5.5.0 The `$args` parameter was added.
* @param string $name The name of the specialised sidebar.
* @param array $args Optional. Additional arguments passed to the sidebar template.
* @return void|false Void on success, false if the template does not exist.
function get_sidebar( $name = null, $args = array() ) {
* Fires before the sidebar template file is loaded.
* @since 2.8.0 The `$name` parameter was added.
* @since 5.5.0 The `$args` parameter was added.
* @param string|null $name Name of the specific sidebar file to use. Null for the default sidebar.
* @param array $args Additional arguments passed to the sidebar template.
do_action( 'get_sidebar', $name, $args );
$templates[] = "sidebar-{$name}.php";
$templates[] = 'sidebar.php';
if ( ! locate_template( $templates, true, true, $args ) ) {
* Loads a template part into a template.
* Provides a simple mechanism for child themes to overload reusable sections of code
* Includes the named template part for a theme or if a name is specified then a
* specialised part will be included. If the theme contains no {slug}.php file
* then no template will be included.
* The template is included using require, not require_once, so you may include the
* same template part multiple times.
* For the $name parameter, if the file is called "{slug}-special.php" then specify
* @since 5.5.0 A return value was added.
* @since 5.5.0 The `$args` parameter was added.
* @param string $slug The slug name for the generic template.
* @param string $name The name of the specialised template.
* @param array $args Optional. Additional arguments passed to the template.
* @return void|false Void on success, false if the template does not exist.
function get_template_part( $slug, $name = null, $args = array() ) {
* Fires before the specified template part file is loaded.
* The dynamic portion of the hook name, `$slug`, refers to the slug name
* for the generic template part.
* @since 5.5.0 The `$args` parameter was added.
* @param string $slug The slug name for the generic template.
* @param string|null $name The name of the specialized template.
* @param array $args Additional arguments passed to the template.
do_action( "get_template_part_{$slug}", $slug, $name, $args );
$templates[] = "{$slug}-{$name}.php";
$templates[] = "{$slug}.php";
* Fires before a template part is loaded.
* @since 5.5.0 The `$args` parameter was added.
* @param string $slug The slug name for the generic template.
* @param string $name The name of the specialized template.
* @param string[] $templates Array of template files to search for, in order.
* @param array $args Additional arguments passed to the template.
do_action( 'get_template_part', $slug, $name, $templates, $args );
if ( ! locate_template( $templates, true, false, $args ) ) {
* 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 {@see '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,
* {@see 'pre_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 5.2.0 The `$args` array parameter was added in place of an `$echo` boolean flag.
* Optional. Array of display arguments.
* @type bool $echo Whether to echo or return the form. Default true.
* @type string $aria_label ARIA label for the search form. Useful to distinguish
* multiple search forms on the same page and improve
* accessibility. Default empty.
* @return void|string Void if 'echo' argument is true, search form HTML if 'echo' is false.
function get_search_form( $args = array() ) {
* Fires before the search form is retrieved, at the start of get_search_form().
* @since 2.7.0 as 'get_search_form' action.
* @since 5.5.0 The `$args` parameter was added.
* @link https://core.trac.wordpress.org/ticket/19321
* @param array $args The array of arguments for building the search form.
* See get_search_form() for information on accepted arguments.
do_action( 'pre_get_search_form', $args );
if ( ! is_array( $args ) ) {
* Back compat: to ensure previous uses of get_search_form() continue to
* function as expected, we handle a value for the boolean $echo param removed
* in 5.2.0. Then we deal with the $args array and cast its defaults.
// Set an empty array and allow default arguments to take over.
// Defaults are to echo and to output no custom label on the form.
$args = wp_parse_args( $args, $defaults );
* Filters the array of arguments used when generating the search form.
* @param array $args The array of arguments for building the search form.
* See get_search_form() for information on accepted arguments.
$args = apply_filters( 'search_form_args', $args );
// Ensure that the filtered arguments contain all required default values.
$args = array_merge( $defaults, $args );
$format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
* Filters the HTML format of the search form.
* @since 5.5.0 The `$args` parameter was added.
* @param string $format The type of markup to use in the search form.
* Accepts 'html5', 'xhtml'.
* @param array $args The array of arguments for building the search form.
* See get_search_form() for information on accepted arguments.
$format = apply_filters( 'search_form_format', $format, $args );
$search_form_template = locate_template( 'searchform.php' );
if ( '' !== $search_form_template ) {
require $search_form_template;
// Build a string containing an aria-label to use for the search form.
if ( $args['aria_label'] ) {
$aria_label = 'aria-label="' . esc_attr( $args['aria_label'] ) . '" ';
* If there's no custom aria-label, we can set a default here. At the
* moment it's empty as there's uncertainty about what the default should be.
if ( 'html5' === $format ) {
$form = '<form role="search" ' . $aria_label . 'method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
<span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
<input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search …', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" />
<input type="submit" class="search-submit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" />
$form = '<form role="search" ' . $aria_label . 'method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
<label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" />
* Filters the HTML output of the search form.
* @since 5.5.0 The `$args` parameter was added.
* @param string $form The search form HTML output.
* @param array $args The array of arguments for building the search form.
* See get_search_form() for information on accepted arguments.
$result = apply_filters( 'get_search_form', $form, $args );
if ( null === $result ) {
* Display the Log In/Out link.
* Displays a link, which allows users to navigate to the Log In page to log in
* or log out depending on whether they are currently logged in.
* @param string $redirect Optional path to redirect to on login/logout.
* @param bool $echo Default to echo and not return the link.
* @return void|string Void if `$echo` argument is true, log in/out link if `$echo` is false.
function wp_loginout( $redirect = '', $echo = true ) {
if ( ! is_user_logged_in() ) {
$link = '<a href="' . esc_url( wp_login_url( $redirect ) ) . '">' . __( 'Log in' ) . '</a>';
$link = '<a href="' . esc_url( wp_logout_url( $redirect ) ) . '">' . __( 'Log out' ) . '</a>';
* Filters the HTML output for the Log In/Log Out link.
* @param string $link The HTML link content.
echo apply_filters( 'loginout', $link );
/** This filter is documented in wp-includes/general-template.php */
return apply_filters( 'loginout', $link );
* Retrieves the logout URL.
* Returns the URL that allows the user to log out of the site.
* @param string $redirect Path to redirect to on logout.
* @return string The logout URL. Note: HTML-encoded via esc_html() in wp_nonce_url().
function wp_logout_url( $redirect = '' ) {
if ( ! empty( $redirect ) ) {
$args['redirect_to'] = urlencode( $redirect );
$logout_url = add_query_arg( $args, site_url( 'wp-login.php?action=logout', 'login' ) );
$logout_url = wp_nonce_url( $logout_url, 'log-out' );
* Filters the logout URL.
* @param string $logout_url The HTML-encoded logout URL.
* @param string $redirect Path to redirect to on logout.
return apply_filters( 'logout_url', $logout_url, $redirect );
* Retrieves the login URL.
* @param string $redirect Path to redirect to on log in.
* @param bool $force_reauth Whether to force reauthorization, even if a cookie is present.
* @return string The login URL. Not HTML-encoded.
function wp_login_url( $redirect = '', $force_reauth = false ) {
$login_url = site_url( 'wp-login.php', 'login' );
if ( ! empty( $redirect ) ) {
$login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_url );
$login_url = add_query_arg( 'reauth', '1', $login_url );
* @since 4.2.0 The `$force_reauth` parameter was added.
* @param string $login_url The login URL. Not HTML-encoded.
* @param string $redirect The path to redirect to on login, if supplied.
* @param bool $force_reauth Whether to force reauthorization, even if a cookie is present.
return apply_filters( 'login_url', $login_url, $redirect, $force_reauth );
* Returns the URL that allows the user to register on the site.
* @return string User registration URL.
function wp_registration_url() {
* Filters the user registration URL.
* @param string $register The user registration URL.
return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
* Provides a simple login form for use anywhere within WordPress.
* The login form HTML is echoed by default. Pass a false value for `$echo` to return it instead.
* Optional. Array of options to control the form output. Default empty array.
* @type bool $echo Whether to display the login form or return the form HTML code.
* @type string $redirect URL to redirect to. Must be absolute, as in "https://example.com/mypage/".
* Default is to redirect back to the request URI.
* @type string $form_id ID attribute value for the form. Default 'loginform'.
* @type string $label_username Label for the username or email address field. Default 'Username or Email Address'.
* @type string $label_password Label for the password field. Default 'Password'.
* @type string $label_remember Label for the remember field. Default 'Remember Me'.
* @type string $label_log_in Label for the submit button. Default 'Log In'.
* @type string $id_username ID attribute value for the username field. Default 'user_login'.
* @type string $id_password ID attribute value for the password field. Default 'user_pass'.