Redirecting post to an external url

goingreen

Regular Member
Joined
May 7, 2010
Messages
309
Reaction score
311
I have the dailynotes - elegant theme which is perfect for advertising.

hxxp://www.elegantthemes.com/preview/DailyNotes/

How do I set it up so that when I click on a post, it directs to a url rather than opening post ?


The post is obviously for an external url for advertising purposes so not every plugin would work. Most of the ones that Ive seen require internal redirection.

Any recommendations for a plugin / code that would work ?
 
try this

Code:
Plugin Name: Redirect Page
Description: Redirects permalink page based on specific meta key
Version: 1.0
*/

$redirect_key = 'link';

## Function: Redirect post if meta key is present 
add_action('template_redirect', 'redirector');

function redirector() {
        global $wp_query, $redirect_key;
        $permalink = get_permalink();
        if(is_single() || is_page()) {


                $redirect = get_post_meta($wp_query->post->ID, $redirect_key, true);

                
                if('' != $redirect) {
                

                        header("HTTP/1.1 301 Moved Permanently");
            header("Location: " . $redirect);
                        
            remove_action('template_redirect', 'redirector');
                return 0;

                        
                }
        }
}



?>
 
Quicker, easier way:

Go to add new plugins and search for "page links to"

Install it and every post or page will have the option at the bottom of the edit area to set a url.

~C
 
try this

Code:
Plugin Name: Redirect Page
Description: Redirects permalink page based on specific meta key
Version: 1.0
*/

$redirect_key = 'link';

## Function: Redirect post if meta key is present 
add_action('template_redirect', 'redirector');

function redirector() {
        global $wp_query, $redirect_key;
        $permalink = get_permalink();
        if(is_single() || is_page()) {


                $redirect = get_post_meta($wp_query->post->ID, $redirect_key, true);

                
                if('' != $redirect) {
                

                        header("HTTP/1.1 301 Moved Permanently");
            header("Location: " . $redirect);
                        
            remove_action('template_redirect', 'redirector');
                return 0;

                        
                }
        }
}



?>

Is this specific to this theme ? Where does this need to be installed ?

Quicker, easier way:

Go to add new plugins and search for "page links to"

Install it and every post or page will have the option at the bottom of the edit area to set a url.

~C

This is useful but not for this particular theme. When your install this with the DailyNotes theme, you have to open the post and then open it again to get the redirect. When looking at the theme, I just want to redirect after clicking the button.
 
Back
Top