twentyeleven_get_first_url

Return the first link from the post content.

Description

(string) twentyeleven_get_first_url(); 

If none found, the post permalink is used as a fallback.

Returns (string)

The first link.


Usage

  1. if ( !function_exists( 'twentyeleven_get_first_url' ) ) { 
  2. require_once '/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = twentyeleven_get_first_url(); 
  7.  

Defined (1)

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

/functions.php  
  1. function twentyeleven_get_first_url() { 
  2. $content = get_the_content(); 
  3. $has_url = function_exists( 'get_url_in_content' ) ? get_url_in_content( $content ) : false; 
  4.  
  5. if ( ! $has_url ) 
  6. $has_url = twentyeleven_url_grabber(); 
  7.  
  8. /** This filter is documented in wp-includes/link-template.php */ 
  9. return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );