WordPress tip: How to get the first link in post

Put the function below in your functions.php file, then use it inside the loop in your template files.

 function get_link_url() 
{
$content = get_the_content();     
$has_url = get_url_in_content( $content );      
return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); 
}

Thanks to Filip Stefansson for the tip!

Web Design

firstlinkpostWordPress

Leave a Reply

Your email address will not be published. Required fields are marked *