Search code examples
wordpressurlurl-rewritingarchive

Wordpress archive pages url change


I have my blog archive to show the months and i can access them by going at

http://www.mysite.com/date/2014/02

Now, i want to change these links to something like

http://www.mysite.com/blog/date/2014/02

without changing the permalinks admin panel setting.

Is it possible to achieve this by coding it?


Solution

  • An idea of what you want can be found here and here.

    Install WP Router, and what you will have at end will be something like this:

    add_action( 'wp_router_generate_routes', 'bl_add_routes', 20 );
    
    function bl_add_routes( $router ) { 
    $route_args = array(
                        'path' => '^blog',
                        'query_vars' => array( ),
                        'page_callback' => 'bl_new_demo_route_callback',
                        'page_arguments' => array( ),
                        'access_callback' => true,
                        'title' => __( 'Blog/Date' ),
                        'template' => array(
                                    'page.php',
                                dirname( __FILE__ ) . '/page.php'
                        )
                );
    
    $router->add_route( 'demo-route-id', $route_args );
    }
    
    function bl_new_demo_route_callback( ) {
        return "Congrats!";
    }
    

    Here is another reading which is more straight forward.