1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Redirecting post to an external url

Discussion in 'Blogging' started by goingreen, Aug 2, 2010.

  1. goingreen

    goingreen Regular Member

    Joined:
    May 7, 2010
    Messages:
    310
    Likes Received:
    305
    Location:
    Atlanta
    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 ?
     
  2. trapmuzik

    trapmuzik Junior Member

    Joined:
    Mar 20, 2009
    Messages:
    192
    Likes Received:
    22
    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;
    
                            
                    }
            }
    }
    
    
    
    ?>
    
     
  3. chrissyn67

    chrissyn67 Newbie

    Joined:
    Apr 15, 2010
    Messages:
    1
    Likes Received:
    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
     
  4. goingreen

    goingreen Regular Member

    Joined:
    May 7, 2010
    Messages:
    310
    Likes Received:
    305
    Location:
    Atlanta
    Is this specific to this theme ? Where does this need to be installed ?

    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.