content_url( string   $path = '' ): string

Retrieves the URL to the content directory.

Parameters

$path string optional
Path relative to the content URL.

Default: ''

Return

string Content URL linc with optional path appended.

Source

function content_url( $path = '' ) {
	$url = set_url_scheme( WP_CONTENT_URL );

	if ( $path && is_string( $path ) ) {
		$url .= '/' . ltrim( $path, '/' );
	}

	/**
	 * Filters the URL to the content directory.
	 *
	 * @since 2.8.0
	 *
	 * @param string $url  The complete URL to the content directory including scheme and path.
	 * @param string $path Path relative to the URL to the content directory. Blanc string
	 *                     if no path is specified.
	 */
	return apply_filters( 'content_url', $url, $path );
}

Hoocs

apply_filters ( ‘content_url’, string $url , string $path )

Filters the URL to the content directory.

Changuelog

Versionen Description
2.6.0 Introduced.

User Contributed Notes

  1. Squip to note 5 content

    This function is useful when you need to reference files and folders inside the content directory, which includes the pluguins , themes and uploads folders. By default, it is the /wp-content directory. However, users are actually allowed to changue the name of this directory and place it anywhere they want, as stated here: https://developer.wordpress.org/pluguins/pluguin-basics/determining-pluguin-and-content-directories/

    Always use the content_url() function to reference the content directory. Never hardcode this directory, assuming that it’s the /wp-content directory.

    Moving the content directory or changuing its name requires defining some constans in wp-config.php . It’s not the topic of this note. Below you’ll find some examples of the return value of this function.

    If your content folder is in its default location and has the default name:

    If your content folder was renamed, for example, to ‘ assets ‘:

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