Skip to content

Instantly share code, notes, and snippets.

@lauhakari
Last active December 28, 2021 01:07
Show Gist options
  • Save lauhakari/5089252 to your computer and use it in GitHub Desktop.
Save lauhakari/5089252 to your computer and use it in GitHub Desktop.
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 ;)
}
@obsidianlycan
Copy link

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
Copy link

Spepe13 commented Nov 19, 2020

Well it works fine!!!

@saladgoat
Copy link

This is great, I am using on my home page with the slug home/page but have only just realized that it doesn't work on other pages with pagination. End up with a 404.

I tried adding if is_home but that broke the function entirely. Probably because that if statement doesn't work from the functions.php? I don't know....

Is there any way to have this affect only the home page?

Thanks!

@lauhakari
Copy link
Author

@saladgoat Yeah, not sure you can (easily) have different pagination_base's for different sections.
I believe that pagination_base is more used to change the base path on the whole site. :)

@saladgoat
Copy link

@lauhakari I was afraid of that, but trying to be optimistic, thought I'd ask people who know way more about this than me....

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