Posted By

visualadvance on 12/13/09


Tagged

redirect wordpress


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

maxvee8
srdjan


Wordpress: Page Redirect Template


 / Published in: PHP
 

A handy little page template for making a page redirect to any url. To use save the code as redirect.php, upload to your theme directory, and then when making a page select "redirect" as your page template. Then just enter ONLY the url you want to redirect to in the body copy for that page.

  1. <?php
  2. /*
  3. Template Name: Redirect
  4. */
  5.  
  6. if (have_posts()) {
  7. the_post();
  8. $pattern = '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@';
  9. preg_match($pattern, get_the_excerpt(), $matches);
  10. if ($matches[0]) header('Location: '.$matches[0]);
  11. else echo 'Enter a URL into your page body text.';
  12. }
  13. ?>

Report this snippet  

You need to login to post a comment.