Some time ago, several of our users complained that pagination on our themes is not working properly. Actually, we have found out that this is not theme related issue and it was caused only if Facebook WordPress plugin was installed and activated on their websites.
Since we were a bit worried about this because it is well known plugin, we have found out that many users or theme authors had the similar problem. And then we came up to solution with handy snippet which will prevent the issue.
When does pagination issue by Facebook WordPress plugin appears?
- Only on homepage
- If you are using “Post name” option in Permalink Settings
- If you are using “Static” homepage option in your Reading Settings which means you are using some custom page template to display your posts in a default loop
The problem with this issue is that WordPress actually generates proper pagination link, (i.e. yourwebsite.com/page/2), but it is somehow always redirected to your home page.
Solution
This handy snippet should do a trick. Make sure it is included somewhere in the functions.php file of your theme.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /* Fix pagination issue caused by Facebook plugin */ function meks_fb_plugin_pagination_fix() { //Check if plugin is activated and if we are on the homepage if(class_exists('Facebook_Loader') && is_front_page()){ global $wp_query; $page = get_query_var('page'); $paged = get_query_var('paged'); //Check if we are trying to reach pagination link if($page > 1 || $paged > 1){ unset($wp_query->queried_object); } } } add_action( 'wp', 'meks_fb_plugin_pagination_fix', 99 ); |
That’s it! Feel free to try it out and let us know if it works for you!