Redirect from post to an external URL
Why would you like to redirect a page’s visitor to an external URL instead of presenting post content?
Well, they may be a dozens of reasons. I found one. I was building a simple product showcase page with cool image scroller based on WordPress and Modest theme from Elegant Themes. Since image scroller contained not only image, but also title and two line entry, it was based on actual posts.
I wanted my users to see these texts, but to not be able to access posts itself. Because there was nothing more than just this image, title and two-line description. That’s why I used URL redirection.
Modest theme can be configured (non-standard setting) to use text put into post excerpts, instead of post body, to render two-line intro text placed over each image. I decided to use this setting and to put actual redirection code into post body.
Just like that! Test it on your own blog, if you don’t believe.
Works like a charm. When post body is reached from anywhere, except actual post page (i.e. from home page, when building image scroller), this code does nothing. When user is actually visiting post page, he or she is immediatelly redirected to given URL.
If you wish to use this solution then remember about writing entire above code as one-liner (above multi-line code is given only for readability):