Created
July 3, 2013 16:09
-
-
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.
This file contains hidden or 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 | |
| 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