Title: links_add_base_url
Published: April 25, 2014
Last modified: May 20, 2026

---

# links_add_base_url( string $content, string $base, string[] $attrs = array('src', 'href') ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#wp--skip-link--target)

Adds a base URL to relative links in passed content.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#description)󠁿

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#parameters)󠁿

 `$content`stringrequired

String to search for links in.

`$base`stringrequired

The base URL to prefix to links.

`$attrs`string[]optional

The attributes which should be processed.

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

## 󠀁[Return](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#return)󠁿

 string The processed content.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#source)󠁿

    ```php
    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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/formatting.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/formatting.php#L5426)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/formatting.php#L5426-L5431)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#related)󠁿

| Used by | Description | 
| [install_plugin_information()](https://developer.wordpress.org/reference/functions/install_plugin_information/)`wp-admin/includes/plugin-install.php` |

Displays plugin information in dialog box form.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/links_add_base_url/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Flinks_add_base_url%2F)
before being able to contribute a note or feedback.