Adds a base URL to relative links in passed content.
By default, this function supports the ‘src’ and ‘href’ attributes.
However, this can be modified via the $attrs parameter.
$contentstringrequired
$basestringrequired
$attrsstring[]optional
Default:array('src', 'href')
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 );
}
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/links_add_base_url