WordPress 301 redirect in Nirvana

  • Author
    Posts
  • #34811
    GaryY

    Hi there,

    I am using the Nirvana theme n my website / blog.

    The blog was originally hosted on blogspot but I now host it on my own website. When I moved the blog I set code in my functions.php file redirect blogspot taffic to a specific post on my own website. A so called wordpress 301 redirect.

    This code works when I used it with a different theme but does not seem to work with Nirvana.
    I put this code in the functions.php file located in the ….themes / Nirvana directory. Is there another specific functions file within the Nirvana theme that I shoould use to p this code?

    CODE:
    function blogger_query_vars_filter( $vars ) {
    $vars[] = “blogger”;
    return $vars;
    }

    add_filter(‘query_vars’, ‘blogger_query_vars_filter’);

    function blogger_template_redirect() {
    global $wp_query;
    $blogger = $wp_query->query_vars[‘blogger’];
    if ( isset ( $blogger ) ) {
    wp_redirect( get_wordpress_url ( $blogger ) , 301 );
    exit;
    }
    }

    add_action( ‘template_redirect’, ‘blogger_template_redirect’ );

    function get_wordpress_url($blogger) {
    if ( preg_match(‘@^(?:https?://)?([^/]+)(.*)@i’, $blogger, $url_parts) ) {
    $query = new WP_Query (
    array ( “meta_key” => “blogger_permalink”, “meta_value” => $url_parts[2] ) );
    if ($query->have_posts()) {
    $query->the_post();
    $url = get_permalink();
    }
    wp_reset_postdata();
    }
    return $url ? $url : home_url();
    }

    #34852
    GaryY

    In addition to the above code I have also tried to achieve a 301 redirect using the PLUGIN “Simple 301 Redirect” Unfortunately it appears that it is impossible to achieve a 301 redirect whilst the Nirvana theme is active.

    Have other users experience with this?

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘WordPress 301 redirect in Nirvana’ is closed to new replies.