12

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.

15

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:      Thomas Scholz <info@toscho.de>
 * Author URI:  http://toscho.de
 * 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
  • 1
    What's the difference between $GLOBALS['wp_rewrite']->pagination_base = 'seite' and $wp_rewrite->search_base = 'buscar'; ? – DarkGhostHunter Jul 1 '12 at 21:05
  • 1
    There are subtle and unintuitive differences between global $var; and $GLOBALS['var']. Doesn’t matter in this case, just keep in mind that the latter form is more reliable and easier to read/understand. – fuxia Jul 1 '12 at 21:09
  • could we do url adress like site.com/2 i just tried that but it says no posts found. – Fatih Toprak Feb 15 '13 at 6:57
  • @FatihToprak I think this would get in conflict with everything: post type page, date archives, custom post types. Not worth the trouble. – fuxia Feb 15 '13 at 8:21
  • @toscho thanks for your replay but i really dont need post type archive and page just want to use it regular category archives. – Fatih Toprak Feb 17 '13 at 1:21
15

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.

  • 11
    Just one small notice, because of how extremely costly $wp_rewrite->flush_rules(); is in terms of performance, you should never use it on init, a much better option is to just visit the Permalink options page, and save the changes a few times, that will flush them for you. – André L Jul 24 '12 at 11:50

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.