esc_url_raw( string $url, string[] $protocols = null ): string

Sanitizes a URL for database or redirect usage.


This function is an alias for sanitize_url() .

See also


The URL to be cleaned.
An array of acceptable protocols.
Defaults to return value of wp_allowed_protocols() .



string The cleaned URL after sanitize_url() is run.

More Information

The esc_url_raw() function is similar to esc_url() (and actually uses it), but unlike esc_url() it does not replace entities for display. The resulting URL is safe to use in database queries and redirects.

Please do not use this function as the only sanitizer for HTTP requests, as this function is unable to sanitize against security attacks such as SSRF.

This function is not safe to use for displaying the URL, use esc_url() instead.


function esc_url_raw( $url, $protocols = null ) {
	return sanitize_url( $url, $protocols );


6.1.0Turned into an alias for sanitize_url() .

User Contributed Notes

  1. Skip to note 2 content

    Right and Wrong usage

    <!-- Right -->
    $url = '';
    $response = wp_remote_get( esc_url_raw( $url ) ); // no need to escape entities
    if ( ! is_wp_error( $response ) ) {
    	echo wp_remote_retrieve_body( $response );
    <!-- Wrong! Use esc_url instead! -->
    <img src="<?php echo esc_url_raw( $url ); ?>" />
    <a href="<?php echo esc_url_raw( $url ); ?>">WordPress</a>

You must log in before being able to contribute a note or feedback.