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

Performs esc_url() for database or redirect usage.


Top ↑

See also

Top ↑



(string) (Required) The URL to be cleaned.


(string[]) (Optional) An array of acceptable protocols. Defaults to return value of wp_allowed_protocols().

Default value: null

Top ↑


(string) The cleaned URL after esc_url() is run with the 'db' context.

Top ↑

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, redirects and HTTP requests.

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

Top ↑


File: wp-includes/formatting.php

function esc_url_raw( $url, $protocols = null ) {
	return esc_url( $url, $protocols, 'db' );

Top ↑


Version Description
2.8.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    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.