content_url( string $path = '' ): string

Retrieves the URL to the content directory.


Parameters

$path string Optional
Path relative to the content URL.

Default: ''


Top ↑

Return

string Content URL link with optional path appended.


Top ↑

Source

File: wp-includes/link-template.php. View all references

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. Blank string
	 *                     if no path is specified.
	 */
	return apply_filters( 'content_url', $url, $path );
}

Top ↑

Hooks



Top ↑

Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 2 content
    Contributed by Eyad

    This function is useful when you need to reference files and folders inside the content directory, which includes the plugins, themes and uploads folders. By default, it is the /wp-content directory. However, users are actually allowed to change the name of this directory and place it anywhere they want, as stated here: https://developer.wordpress.org/plugins/plugin-basics/determining-plugin-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 changing its name requires defining some constants 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.