[wp-hackers] Page Redirect from Shortcode
Claude Needham
gxxaxx at gmail.com
Thu Oct 6 15:32:13 UTC 2011
On Thu, Oct 6, 2011 at 6:17 AM, Christopher Ross <cross at thisismyurl.com> wrote:
> Claude, I have a code snippet at http://thisismyurl.com/blog/2011/01/19/redirecting-a-wordpress-post-with-custom-fields/ that will do it, although looking at it ... i should really update that so it's better.
>
> Here's a better function for your functions.php file that will fire before WordPress generates the page.
>> function thisismyurl_redirect() {
>>
>> if ( is_single() ) {
>> 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','thisismyurl_redirect');
> Now, add a custom field to your Post named "redirect" and if it's present, it'll cause a redirect.
>
Christopher,
Thanks for the great head start on the code.
It gives me the perfect start. I can insert my cookie code. Look to
see if it is time to redirect or let them through to the desired page.
Very nice.
Thanks,
Claude
More information about the wp-hackers
mailing list