Pages

Showing posts with label permalink. Show all posts
Showing posts with label permalink. Show all posts

Tuesday, December 10, 2013

How to change Custom Taxonomy Links?


function custom_term_link_url($content) {
    $current_path = 'live-topics';
    $new_path = 'live/topic';
    $content = str_replace($current_path, $new_path, $content);
    return $content;
}
add_filter('term_link', 'custom_term_link_url');

function add_query_vars_for_live_topics($aVars) {
    $aVars[] = "live-topics";    // represents the name of the product category as shown in the URL
    return $aVars;
}
add_filter('query_vars', 'add_query_vars_for_live_topics');

function add_rewrite_rules_live_topics($aRules) {
    $aNewRules = array('live/topic/([^/]+)/?$' => 'index.php?live-topics=$matches[1]');
    $aRules = $aNewRules + $aRules;
    return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules_live_topics');

Monday, June 24, 2013

Redirect to home page if query string not match to value - wordpress


Please add below code to "functions.php" for generating the query string:

function add_query_vars($aVars) {
    $aVars[] = "mode";
    return $aVars;
}

add_filter('query_vars', 'add_query_vars');

function add_rewrite_rules($aRules) {
    $aNewRules = array('news/([^/]+)/?$' => 'index.php?pagename=news&mode=$matches[1]');
    $aRules = $aNewRules + $aRules;
    return $aRules;
}

add_filter('rewrite_rules_array', 'add_rewrite_rules');

function wp_redirect_to_homepage( $query ) {    
 if ( $query->is_main_query() && ( $query->query_vars['pagename'] == 'news') ){         
        if( ( array_key_exists( 'mode', $query->query_vars ) && (trim($query->query_vars['mode']) != 'follow' && trim($query->query_vars['mode']) != 'like'))) {
            wp_redirect( get_permalink($query->queried_object_id) );
            exit;
        }   
    }
}
add_action( 'parse_query', 'wp_redirect_to_homepage' );


Also you can see below URL:
http://stackoverflow.com/questions/14669336/redirect-if-wordpress-query-string-is-empty 
Its very good example for rewrite query string.