links_add_base_url

Add a Base url to relative links in passed content.

Description

(string) links_add_base_url( (string) $content, (string) $base, (array) $attrs = array() ); 

By default it supports the src and href attributes. However this can be changed via the 3rd param.

Returns (string)

The processed content.

Parameters (3)

0. $content (string)
String to search for links in.
1. $base (string)
The base URL to prefix to links.
2. $attrs — Optional. (array) => array()
The attributes which should be processed.

Usage

  1. if ( !function_exists( 'links_add_base_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // String to search for links in. 
  5. $content = ''; 
  6.  
  7. // The base URL to prefix to links. 
  8. $base = ''; 
  9.  
  10. // The attributes which should be processed. 
  11. $attrs = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = links_add_base_url($content, $base, $attrs); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/formatting.php  
  1. function links_add_base_url( $content, $base, $attrs = array('src', 'href') ) { 
  2. global $_links_add_base; 
  3. $_links_add_base = $base; 
  4. $attrs = implode('|', (array)$attrs); 
  5. return preg_replace_callback( "!($attrs)=(['\"])(.+?)\\2!i", '_links_add_base', $content );