Get link value only from the_content()?

You can scan the content to see whether it contains a link and then parse it to find the href attribute. There are many ways to do this, this example uses the built-in kses functionality, as demonstrated by Otto:

$post_link = get_the_permalink();
if ( preg_match('/<a (.+?)>/', get_the_content(), $match) ) {
    $link = array();
    foreach ( wp_kses_hair($match[1], array('http')) as $attr) {
        $link[$attr['name']] = $attr['value'];
    }
    $post_link = $link['href'];
}

Leave a Comment