Posted By

visualadvance on 12/13/09


redirect wordpress

Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


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. */
  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  


RSS Icon Subscribe to comments
Posted By: on November 10, 2018

the 8 best way to heat baby bottle best2by

You need to login to post a comment.