queried_object); if ($link !== false) { wp_redirect(esc_url($link), 301); exit; } } return $headers; } // This section will replace every instance of the permalink with the redirect URL. add_filter('page_link', 'redirect_by_custom_field', 10, 2); add_filter('post_link', 'redirect_by_custom_field', 10, 2); function redirect_by_custom_field($link, $postarg = null) { global $post; if (is_object($postarg)) $id = $postarg->ID; else if (is_int($postarg)) $id = $postarg; else if (is_object($post)) $id = $post->ID; else return $link; $redirect = get_post_meta($id, 'redirect', true); if ($redirect) { if (is_array($redirect)) $redirect = $redirect[0]; $link = $redirect; } return $link; }