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!