开发者

Rewrite (translate) paged part of a URL in Wordpress

I would like to translate the paged part of a URL, like 开发者_JS百科so: currently: mysite.com/page/2 I would like: mysite.com/p/2

Does anybody know of a filter to do this? Or would a custom rewrite be more appropriate? If yes, how?

Thanks, Regards.


OK add this below code in your theme function.php file

and reset you permalink

add_action( 'init', 'my_custom_page_word' );
function my_custom_page_word() {
global $wp_rewrite;
$wp_rewrite->pagination_base = "p";
}

Thank you
Manzurul


You need an action, not a filter.

This function will work directly with your translation package, formatting your new base and prevent to run more than once the flush_rewrite_rules function avoiding bad performance of your blog.

function my_change_rewrite_base() {
    global $wp_rewrite;
    $bases = array(
        'author' => __('Author'), 
        'search' => __('Search'), 
        'comments' => __('Comments)', 
        'pagination' => __('Page')
    );

    foreach ($bases AS $key => $base) {
        $wp_rewrite->{$key} = remove_accents(mb_strtolower($base));
    }

    if ( ! get_option('my_change_rewrite_base_flushed', false) ) {
        flush_rewrite_rules();
        update_option( 'my_change_rewrite_base_flushed', time());
    }
}
add_action('init', 'my_change_rewrite_base');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜