links_add_base_url( string $content, string $base, array $attrs = array(‘src’, ‘href’) ): string

Adds a base URL to relative links in passed content.

Description

By default, this function supports the ‘src’ and ‘href’ attributes.
However, this can be modified via the $attrs parameter.

Parameters

$contentstringrequired
String to search for links in.
$basestringrequired
The base URL to prefix to links.
$attrsarrayoptional
The attributes which should be processed.

Default:array('src', 'href')

Return

string The processed content.

Source

function links_add_base_url( $content, $base, $attrs = array( 'src', 'href' ) ) {
	global $_links_add_base;
	$_links_add_base = $base;
	$attrs           = implode( '|', (array) $attrs );
	return preg_replace_callback( "!($attrs)=(['\"])(.+?)\\2!i", '_links_add_base', $content );
}

Changelog

VersionDescription
2.7.0Introduced.

User Contributed Notes

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