Redirect to URL from Title

Imagine that you run an online-magazine. at some time you may need (or want) to redirect your readers to another website right from your homepage, without having them to read trough your post and click the link there. You could use a plugin OR you simply use custom field magic.

Now all you need to do is to add a custom field called “redirect” (this is case-sensitive) with your desired url as value. Now, when your readers click on a certain title on your homepage, they will be redirected to the other website.

Code Snippet:

// Search for something that looks similar to this in your index.php
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>

 // and replace it with

<a href="<?php $redirect = get_post_meta($post->ID, 'redirect', true);
if ($redirect != "") { echo $redirect; } else { the_permalink(); } ?>" rel="bookmark">
<?php the_title(); ?></a>

Posted in Posts