status_header() WordPress Function

The status_header() function is used to set the HTTP response code in the header of the page. This is useful for indicating the status of a page or post, for example, a 404 page not found error.

status_header( int $code, string $description = '' ) #

Set HTTP status header.


Description

Top ↑

See also


Top ↑

Parameters

$code

(int)(Required)HTTP status code.

$description

(string)(Optional) A custom description for the HTTP status.

Default value: ''


Top ↑

More Information

Usage:
status_header( $header );
Notes:

Uses: apply_filters() Calls ‘status_header‘ on status header string, HTTP code, HTTP code description, and protocol string as separate parameters.


Top ↑

Source

File: wp-includes/functions.php

function status_header( $code, $description = '' ) {
	if ( ! $description ) {
		$description = get_status_header_desc( $code );
	}

	if ( empty( $description ) ) {
		return;
	}

	$protocol      = wp_get_server_protocol();
	$status_header = "$protocol $code $description";
	if ( function_exists( 'apply_filters' ) ) {

		/**
		 * Filters an HTTP status header.
		 *
		 * @since 2.2.0
		 *
		 * @param string $status_header HTTP status header.
		 * @param int    $code          HTTP status code.
		 * @param string $description   Description for the status code.
		 * @param string $protocol      Server protocol.
		 */
		$status_header = apply_filters( 'status_header', $status_header, $code, $description, $protocol );
	}

	if ( ! headers_sent() ) {
		header( $status_header, true, $code );
	}
}


Top ↑

Changelog

Changelog
VersionDescription
4.4.0Added the $description parameter.
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More