Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created September 20, 2011 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/1229367 to your computer and use it in GitHub Desktop.
Save billerickson/1229367 to your computer and use it in GitHub Desktop.
Find URL in post
<?php
//** Website: http://links.billerickson.net/
//** In functions.php: **//
// Find URL in post
function be_find_url( $content ) {
preg_match( '|href=["]([^\'^"]+)["]|mi', $content, $m );
return $m[1];
}
//** In the loop (for testing) **//
$content = get_the_content();
echo 'URL: ' . be_find_url( $content );
//** Final goal, update RSS permalink to point to link and not single URL **//
// Change RSS permalink to url
add_filter( 'the_permalink_rss', 'be_rss_permalink' );
function be_rss_permalink( $permalink ) {
$url = be_find_url( $wp_query->$post->post_content );
if( !empty( $url ) ) return $url;
else return $permalink;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment