Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

wp_is_xml_request

Function Description:

Checks whether current request is an XML request, or is expecting an XML response.

Function Examples:

⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Checking if the current request is an XML request
if ( wp_is_xml_request() ) {
    // Handle XML request here
} else {
    // Handle non-XML request here
}
// Example 2: Using wp_is_xml_request to conditionally enqueue scripts
add_action( 'wp_enqueue_scripts', 'my_custom_scripts' );
function my_custom_scripts() {
    if ( wp_is_xml_request() ) {
        // Enqueue XML-specific scripts here
    } else {
        // Enqueue non-XML scripts here
    }
}
// Example 3: Redirecting XML requests to a custom XML feed
add_action( 'template_redirect', 'redirect_xml_requests' );
function redirect_xml_requests() {
    if ( wp_is_xml_request() ) {
        wp_redirect( home_url( '/custom-xml-feed/' ) );
        exit;
    }
}