After setting up and installing themes in your Wordpress blog, you’ll soon discover some great uses for customized templates. For instance, if you need to add a link back to your static website home page, you can use the Wordpress function “wp_redirect()” and a custom template to do this. You may ask, why not install one of the many “redirect” plugins, it’s fast and you don’t need to dig into templates or functions. But you may find that those plugins actually slow down your blog. Not a good thing! So, instead of using a ready-built plugin, try this customized method.

In your favorite text editor, create a PHP page, here I called it “redirect” and then make sure that it is also your Template Name:


<?php
/*
Template Name: redirect
*/
?>
<?php wp_redirect('http://yoursite.com'); exit();
?>

Upload the redirect.php page to your wp-content theme folder. Create a page to serve as your redirect page and make sure to set its template attribute to “redirect.”

Select Redirect Template

Select Redirect Template

I found another use for customized templates when using plugins, too! Most themes will use page templates that include comments area. What if you have a utility page such as a sitemap using a plugin and you don’t want the wp_comments to appear for that page. Simply open the page.php in your theme, save as “no_comments.php” and remove the comments_template() function. Save your “no_comments” template and upload to the wp-content theme folder. Use it for your sitemap or other utility pages.

Why do redirect plugins cause a slowdown of your blog? My theory is that since a theme page used to contain the redirect plugin more than likely uses all the function calls to create the page structure — get_header(), get_sidebar(), get_footer(), etc. So, your page is trying to be dynamically created using database information and PHP code while it is being redirected to another url. I suppose it really all depends on what is happening first — the function to redirect, or the building of the page? To find out, I’ll have to dig into the plugin code.

Anyway, it seems that the customized template together with the wp_redirect() function is faster. What do you think?