Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Twenty Links - Redirect single posts
// in functions.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' );
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