Created
September 20, 2011 15:14
-
-
Save billerickson/1229367 to your computer and use it in GitHub Desktop.
Find URL in post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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