Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Twenty Links - Redirect single posts

View gist:1250866
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?php
// Find URL in post
function be_find_url( $content ) {
preg_match( '|href=["]([^\'^"]+)["]|mi', $content, $m );
return $m[1];
}
// Redirect single posts to linked URL
function be_redirect_on_single() {
if( is_single() ) {
global $post;
$url = be_find_url( $post->post_content );
if( empty( $url ) ) return;
wp_redirect( $url, '301' );
exit;
}
}
add_action( 'template_redirect', 'be_redirect_on_single' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.