Wordpress pagination stops working after page 10 - wordpress

For some reason after getting to page 10 in my blog(ex: /page/10) -- the page goes to a 404.
When go to example.com/page/11 it redirects me here:
https://example.wpengine.com/blog/pagehttps:/example.wpengine.com/
Cannot figure out what is going on here.

Put this code on function.php file:
/**
* Fix pagination on archive pages
* After adding a rewrite rule, go to Settings > Permalinks and click Save to flush the rules cache
*/
function my_pagination_rewrite() {
add_rewrite_rule('blog/page/?([0-9]{1,})/?$', 'index.php?category_name=blog&paged=$matches[1]', 'top');
}
add_action('init', 'my_pagination_rewrite');
Replace blog with your category name in the code above.
After adding this code, You can go to Settings > Permalinks
After, click Save to flush the rules cache, or else the rule will not be applied.
Get the more details about the solution, you can follow the article - Fixing a WordPress pagination 404 error

Related

Wordpress automatically created a redirect that I need removed

I made an edit to a page on a Wordpress site that included changing its parent. Unfortunately I was not paying attention and this move somehow changed the permalink/slug which I saved before noticing. In addition Wordpress automatically created a 301 redirect to go from the original URL to this new URL. I went back in and changed the permalink/slug back to the original but that redirect still stands so it stills sends the page to the new url it created rather than keeping it to updated option (updated meaning me typing in the original slug).
I am looking for a way to remove the 301 redirect, but do not know where to start.
The original URL: https://www.synergex.com/rev11
The newly generated URL: https://www.synergex.com/products/synergy-de-rev11-licensing-faq
I also tried simply creating a brand new page using the original slug/permalink /rev11 but it gets changed to /rev11-2 so it seems like it it must remember the /rev11 somewhere.
I am hoping there is a way to do this through the WP Dashboard and am open to suggestions. This site does have the Redirection plugin installed but I've checked through the lists and this redirect was not created or listed in it. I also tried to add a redirect to do the opposite (redirect from the new URL to old) but of course it just created a loop that timed out.
EDIT 1.2: You probably have a problem with your old permalinks not getting flushed properly. But do not worry the great people at Wordpress got a function for that called flush_rewrite_rules();
Remove rewrite rules and then recreate rewrite rules. This function is
useful when used with custom post types as it allows for automatic
flushing of the WordPress rewrite rules (usually needs to be done
manually for new custom post types). However, this is an expensive
operation so it should only be used when necessary.
Source # https://developer.wordpress.org/reference/functions/flush_rewrite_rules/
Add the following to the top of your function.php:
<?php
/**
* Removes a function from a specified filter hook.
* More about flush_rewrite_rules(); # https://developer.wordpress.org/reference/functions/flush_rewrite_rules/
*/
flush_rewrite_rules();
/*
* Remove rewrite rules and then recreate rewrite rules.
* More about remove_filter(); # https://developer.wordpress.org/reference/functions/remove_filter/
*/
remove_filter( 'template_redirect', 'redirect_canonical' ); ?>

Wordpress - URL wild card id loads root permalink

I have a Wordpress page called "Design" with the permalink "/design"
It loads as expected. What I am trying to do is to tell wordpress or my htaccess file that if I want to go to a url like:
domain.com/design/123abc
It will still load the /design permalink but keep the "123abc" appened to the url. I am not looking for a redirect. I just want wordpress to load the page and ignore everything after "/design/"
Is this possible?
Found my answer. Added this script in my child theme functions.php
24565 is the id of the /design page
function custom_rewrite_basic() {
add_rewrite_rule('^design/*', '/index.php?page_id=24565', 'top');
}
add_action('init', 'custom_rewrite_basic');

Woocommerce Add_Rewrite_Rule Not Working For Shop Page

I want below URL:
https://www.example.com/shop/keyword/
to work as below URL. (below one works well.)
https://www.example.com/shop/?search_text=keyword
I can achieve this behaviour for my /search/ page when I add the following code to functions.php.
function my_rewrite_rule() {
add_rewrite_rule('^search/([^/]*)?','index.php?pagename=search&search_text=$matches[1]','top');
}
but same code is not working for /shop/ page.
Normal behaviour should be to lists all the products. However /shop/ page URL shows no results.
Edit: It doesn't work even after permalinks are refreshed.
I might not fully understand your question, but is this what your trying to do?
If so, the WooCommerce query for the /shop/ archive matches post_type=product.
Try this rewrite rule and flush your permalinks by going to Settings->Permalinks in the WordPress dashboard and then clicking the save button.
/**
* Add rewrite rule from `/shop/keyword/` to `shop/?search_text=keyword`
*
* #link https://stackoverflow.com/questions/56467044/woocommerce-add-rewrite-rule-not-working-for-shop-page
*/
add_action( 'init', function (): void {
add_rewrite_rule(
'^shop/([^/]*)?',
'index.php?post_type=product&search_text=$matches[1]',
'top'
);
} );

Make WordPress show the same page on two different url patterns

I need to make WordPress show the same page on two different URLs:
https://sitename.com/%postname%/
https://sitename.com/%postname%/tail/
* I can only use functions.php
I used a few similar cases and guides and here is code which worked out for me:
function tail_rewrite()
{
add_rewrite_rule('^([^/]*)/tail?', 'index.php?name=$matches[1]', 'top');
// first parameter for posts: p or name, for pages: page_id or pagename
}
add_action('init', 'tail_rewrite');
don't forget to flush the rules by visiting Settings > Permalinks
OR use flush_rewrite_rules() in the plugin activation (don't execute it at every page load).

How can I change the WordPress archive URL pattern?

I have an archives section in the right sidebar. You can check here. By default, the archive section gives the /blog/2012/08/ URL pattern.
But I want the /blog/archive/2012/08/ pattern without changing the Permalink pattern as the main posts using blog/post_name, and it should not be changed. How can I get this done?
I am new to WordPress.
Tonight I come to this question with no answer. Although it's quite late to answer, but I try to answer it for future reference.
You can add following code snippet to functions.php file.
function change_archive_links() {
global $wp_rewrite;
// add 'archive'
$wp_rewrite->date_structure ='blog/archive/%year%/%monthnum%/';
}
add_action('init','change_archive_links');
Don't forget to flush WordPress rewrite rules after adding the snippet. To do that, go to WP Dashboard > Settings > Permalinks and press Save Changes button.

Resources