Skip to content

Instantly share code, notes, and snippets.

@caseymhunt
Created July 3, 2013 16:09
Show Gist options
  • Select an option

  • Save caseymhunt/5919890 to your computer and use it in GitHub Desktop.

Select an option

Save caseymhunt/5919890 to your computer and use it in GitHub Desktop.
A function for Wordpress (functions.php) that will redirect (301) using the value in a custom field named 'redirect.' Special thanks to: http://thisismyurl.com/6598/wordpress-redirect-single-post/ -- code originally from there, edited to suit my needs.
<?php
function thecasey_redirect() {
if ( is_page() ) {
global $post;
$post_id = $post->ID;
if ( !empty( $post_id ) )
$redirect = get_post_meta ( $post_id, 'redirect', true);
if ( ! empty( $redirect ) ) {
wp_redirect( $redirect, 301 );
exit();
}
}
}
add_action( 'template_redirect', 'thecasey_redirect' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment