If you want to create custom pagination permalink in WordPress? Use following code in your theme’s functions.php file OR in site specific plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // Removes the canonical redirection remove_filter( 'template_redirect', 'redirect_canonical' ); // Add custom rewrite rules add_action( 'init', 'my_add_custom_rewrite_rules' ); function my_add_custom_rewrite_rules() { // Slug of the target page $page_slug = 'heartbreaking-photos'; // Page number to replace $page_num = 2; // Title you wish to replace the page number with $title = 'custom-string'; // Add the custom rewrite rule add_rewrite_rule( '^' . $page_slug . '/' . $title . '/?$', 'index.php?pagename=' . $page_slug . '&page=' . $page_num, 'top' ); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.