Using WordPress ‘get_status_header_desc()’ PHP function

The get_status_header_desc() WordPress PHP function retrieves the description for the HTTP status.

Usage

get_status_header_desc( $code );

Custom example:

$status_description = get_status_header_desc( 404 );
echo $status_description; // Output: "Not Found"

Parameters

  • $code (int) – Required. The HTTP status code.

More information

See WordPress Developer Resources: get_status_header_desc()

Examples

Display HTTP Status Description for a 200 Code

This example retrieves the description for a 200 HTTP status code.

$status_description = get_status_header_desc( 200 );
echo $status_description; // Output: "OK"

Display HTTP Status Description for a 403 Code

This example retrieves the description for a 403 HTTP status code.

$status_description = get_status_header_desc( 403 );
echo $status_description; // Output: "Forbidden"

Display HTTP Status Description for a 500 Code

This example retrieves the description for a 500 HTTP status code.

$status_description = get_status_header_desc( 500 );
echo $status_description; // Output: "Internal Server Error"

Display HTTP Status Description for a 503 Code

This example retrieves the description for a 503 HTTP status code.

$status_description = get_status_header_desc( 503 );
echo $status_description; // Output: "Service Unavailable"

Display HTTP Status Description for an Invalid Code

This example retrieves the description for an invalid HTTP status code.

$status_description = get_status_header_desc( 12345 );
echo $status_description; // Output: ""

Tagged in

Leave a Comment

Your email address will not be published. Required fields are marked *