Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Change the pagination url in Wordpress (3+) You can put in a plugin file or your functions.php.
<?php
add_action( 'init', 'my_custom_page_word' );
function my_custom_page_word() {
global $wp_rewrite; // Get the global wordpress rewrite-rules/settings
// Change the base pagination property which sets the wordpress pagination slug.
$wp_rewrite->pagination_base = "new-slug"; //where new-slug is the slug you want to use ;)
}
@snaever

This comment has been minimized.

Copy link

@snaever snaever commented Mar 28, 2014

Hi,

This doesn't seems to work anymore. When I go to domain.com/new-slug/2 it gives me the 404 page. Do you have an updated version of this?

Thanks.

@lauhakari

This comment has been minimized.

Copy link
Owner Author

@lauhakari lauhakari commented Aug 23, 2014

Hey.
Sorry I haven't answered earlier, haven't seen your question. Can't really remember when or how I used this, prpably should've made a note to myself :P

Anyway, you can check whats in your current rewrite rules if your do this:

global $wp_rewrite;
echo '<pre>';
print_r($wp_rewrite);
echo '</pre>';

Maybe you can find the paginate property there? :)

@stefanoortisi

This comment has been minimized.

Copy link

@stefanoortisi stefanoortisi commented Jun 8, 2015

Your code works for the pagination on homepage.
Do you have an idea about how to change the slug even for category pagination?

@maryisdead

This comment has been minimized.

Copy link

@maryisdead maryisdead commented Mar 8, 2018

Works fine with 4.9.4.

And a heads-up: You need to save your permalinks to make this work.

@piotrbox

This comment has been minimized.

Copy link

@piotrbox piotrbox commented May 10, 2018

Hey, this works on standard posts, but not on custom post type (gives 404 - als ofter saving permalinks), any way to make ot work for CPT? also is there a way to lose the sug completly (like domain.com/customcat/2 ) now when i live new slug blank i get "//" ( domain.com/postcat//2.

thanx

@morvy

This comment has been minimized.

Copy link

@morvy morvy commented Jan 15, 2019

Had the same problem, for me the pagination doesn't work for WooCommerce, but after checking all rewrite rules I found out that the permalink structure for WooCommerce is not using pagination_base at all, so find the extra_rules_top rule that has "page" in it and reuse the rewrite rule like this:

unset($wp_rewrite->extra_rules_top["eshop/page/([0-9]{1,})/?$"]);
$wp_rewrite->extra_rules_top['eshop/new-slug/([0-9]{1,})/?$'] = 'index.php?post_type=product&paged=$matches[1]';
@obsidianlycan

This comment has been minimized.

Copy link

@obsidianlycan obsidianlycan commented Apr 18, 2020

Ah is there anyway to strip the / before the page number? I am trying to re-write to /?=page_2/ and this method drops a / before the 2.

@Spepe13

This comment has been minimized.

Copy link

@Spepe13 Spepe13 commented Nov 19, 2020

Well it works fine!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment