Simple question. When pagination is activated, the URL changes to "site.com/page/2". For my site, this should be "site.com/paggetto/2".
How can I change that rewrite rule? I also want to change "author" and other variables.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
For some sites in German I use the following plugin to translate page to seite (the German word for page):
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 Page to Seite
* Description: Ersetzt <code>/page/</code> durch <code>/seite/</code>.
* Author: Fuxia Scholz
* License: MIT
* License URI: http://www.opensource.org/licenses/mit-license.php
*/
if ( ! function_exists( 't5_page_to_seite' ) )
{
register_activation_hook( __FILE__ , 't5_flush_rewrite_on_init' );
register_deactivation_hook( __FILE__ , 't5_flush_rewrite_on_init' );
add_action( 'init', 't5_page_to_seite' );
function t5_page_to_seite()
{
$GLOBALS['wp_rewrite']->pagination_base = 'seite';
}
function t5_flush_rewrite_on_init()
{
add_action( 'init', 'flush_rewrite_rules', 11 );
}
}
Note that you flush the rewrite rules on de/activation only. You will need a separate rewrite rule in your .htaccess to redirect old URLs to the new ones:
RedirectMatch Permanent ^/(.*)/page/(.*) /$1/seite/$2
Method 2
Figured out:
function re_rewrite_rules() {
global $wp_rewrite;
// $wp_rewrite->author_base = $author_slug;
// print_r($wp_rewrite);
$wp_rewrite->author_base = 'autor';
$wp_rewrite->search_base = 'buscar';
$wp_rewrite->comments_base = 'comentarios';
$wp_rewrite->pagination_base = 'pagina';
$wp_rewrite->flush_rules();
}
add_action('init', 're_rewrite_rules');
At least, that will do the job.
Method 3
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');
Method 4
The following worked for me:
function nw_strana() {
$GLOBALS['wp_rewrite']->pagination_base = 'strana';
}
add_action( 'init', 'nw_strana' );
function nw_rewrite( $rules ) {
$new_rules = array(
'obchod/strana/([0-9]{1,})/?$' => 'index.php?post_type=product&paged=$matches[1]',
);
$rules = array_merge( $new_rules, $rules );
return $rules;
}
add_filter( 'rewrite_rules_array', 'nw_rewrite' );
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0