•  

Creating a Custom Redirect Page Template in WordPress

Pin It

I wanted to redirect a couple pages from in a menu that I was working on recently.  It seemed like something that might be useful to others, so here is an example of a WordPress custom redirect page.  You will notice I called the template Redirect.  Remember to put this new template into your theme directory, or if your using a child theme put it in the child theme directory. save the page as redirect.php or you can name it any other structure you like as long as it is a php file.

Below the complete code for a redirect page template:

<?php
/*
Template Name: Redirect
*/
?>

<?php if (have_posts()) : the_post(); ?>

<?php $URL = get_the_excerpt(); if (!preg_match('/^http:\/\//', $URL)) $URL = 'http://' . $URL; ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Refresh" content="0; url=<?php echo $URL; ?>">
</head>

<body>
</body>
</html>

<?php endif; ?>

Now what? How to Use The Redirect Page

  1. Go to Pages and create a new Page. On the right hand sidebar click the Page Template dropdown, select Redirect
  2. Add the URL to the content of the page that you would like to redirect to e.g. http://www.designshifts.com/digital-paintings-bobby-chiu/
  3. Publish the page and now the new link for http://www.designshifts.com/creating-a-custom-redirect-page-template-wordpress will be http://www.designshifts.com/digital-paintings-bobby-chiu/

Pretty simple and can be very useful.  Leave a comment if you have anything to add.  Hope this helps!

Topher

Chris has a real passion for design and loves to share inspiration and tutorials with the design community. He's the curator here at designshifts.com, a freelance web consultant and developer and has a passion for the great outdoors.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle Plus

Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

5 Comments

  1. Posted May 25, 2011 at 3:57 pm | Permalink

    You created some great factors there. I did a search around the subject and found most people will agree with
    your blog.

  2. Confused
    Posted July 29, 2011 at 8:04 pm | Permalink

    Why would you use an HTML redirect? Why not just use a PHP header redirect? i.e.


    <?php
    /*
    Template Name: Redirect
    */

    if (have_posts()) : the_post();

    $URL = get_the_excerpt(); if (!preg_match('/^http:\/\//', $URL)) $URL = 'http://&#039; . $URL;

    header( 'Location: http://www.yoursite.com/new_page.html&#039; ) ;

    endif;

  3. Confused
    Posted July 29, 2011 at 8:06 pm | Permalink

    oops. meant to say:


    <?php
    /*
    Template Name: Redirect
    */

    if (have_posts()) : the_post();

    $URL = get_the_excerpt(); if (!preg_match('/^http:\/\//', $URL)) $URL = 'http://&#039; . $URL;

    header( "Location: $URL" ) ;

    endif;

  4. Posted September 5, 2011 at 4:33 pm | Permalink

    Hi
    I’m going to spare more time thinking about this post

  5. Mina
    Posted December 15, 2011 at 3:28 pm | Permalink

    This is AWESOME. I couldn’t figure out how to redirect the page. I’m new to WordPress and those darn Permalinks were confusing me. Your explanation is very straightforward, and best of all is worked!

    Thanks for the fabulous help!

One Trackback

  1. By Zendesk Integration with Cart66 on February 8, 2011 at 1:52 pm

    [...] and include a link directly to the members only forum. Or, you may want to make use of a WordPress Redirect Page Template so you can define Cart66 access permissions for the [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • WOOD Skateboard Rings