Blog Pagination Next and Prev ( rel=next/rel=prev ) Not Showing in Source Code

#993532
  • Resolved Jordan Dick
    Rank Math free

    Would you be able to assist in correctly implementing the rel=next/rel=prev attributes on paginated blog pages?

    1) I just inherited this site to manage. Initially, all blog paginations had a canonical link in the source code pointing to camppontiac.com/blog/ as opposed to camppontiac.com/blog/page/2/, camppontiac.com/blog/page/3/, etc. I rectified this issue using a snippet of code I found on your site here: https://support.rankmath.com/ticket/canonical-pagination-4/. So issue #1 is fixed.

    2) The one remaining issue is that the rel=”next” and rel=”prev” links are not showing in the source code for blog index and blog paginated pages. I have tried disabling all plugins and using the default WordPress theme but have had no luck with the described issues. The only thing that worked to fix issue #1 was the snippet I mentioned above. To fix the second issue, I was wondering if there is a way to force the rel/prev links to show in the source code.

    Blog page(s) with issue
    https://camppontiac.com/blog/page/2/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    I apologize for the issue you are facing with the rel="next" and rel="prev" attributes not showing in the source code for your paginated blog pages. Thank you for providing the details about the steps you’ve already taken to resolve the canonical link issue.

    To ensure that the rel="next" and rel="prev" tags are correctly implemented, please follow these steps:

    1. Check Rank Math Settings: Make sure that you have enabled pagination settings in Rank Math. You can do this by navigating to WordPress Dashboard → Rank Math SEO → Titles & Meta → Misc. Pages. Ensure that the pagination settings are configured correctly.

    2. Theme Compatibility: Since you mentioned trying the default WordPress theme, it’s important to ensure that your current theme supports pagination properly. Some themes may not implement these tags correctly. If you are using a custom theme, consider checking the theme’s functions.php file or template files for pagination support.

    3. Custom Code: If the above steps do not resolve the issue, you might need to add custom code to your theme’s functions.php file to force the output of these tags. Here’s a snippet you can use:

      function add_next_prev_links() {
         if (is_home() || is_archive()) {
             global $wp_query;
             if ($wp_query->max_num_pages > 1) {
                 echo '';
                 echo '';
             }
         }
      }
      add_action('wp_head', 'add_next_prev_links');

      This code checks if you are on a blog or archive page and adds the rel="next" and rel="prev" links accordingly.

    4. Clear Cache: After making changes, ensure to clear any caching plugins you may have active, as well as your browser cache, to see the updates reflected in the source code.

    5. Testing: After implementing these changes, check the source code of your paginated pages again to see if the rel="next" and rel="prev" attributes appear as expected.

    If you continue to experience issues after trying these steps, please reply to this ticket with any additional details or errors you encounter, and a human agent from our support team will assist you further.

    Thank you for your patience, and we hope this helps resolve your issue!

    Sources:
    How to NoIndex Paginated Pages » Rank Math

    Jordan Dick
    Rank Math free

    Hi there, I added the code snippet to functions.php and dumped the CloudFlare cache and browser cache. Still no rel=next/prev links in the source code.

    Hello,

    Can you please confirm if your blog page is an actual archive page or is it derived from a template?

    Rank Math by default should automatically generate the respective adjacent links (rel next and prev) without any custom codes for archive pages.

    Please try using the following code and see if this resolves your issue:

    add_filter( "rank_math/frontend/next_rel_link", function( $link ) {
    	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	
    	if(is_paged()){
    		$link = '<link rel="next" href="'. get_site_url() .'/blog/page/' . $paged + 1 .'" />';
    	}
    	return $link;
    });
    
    add_filter( "rank_math/frontend/prev_rel_link", function( $link ) {
    	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	
    	if(is_paged()){
    		$link = '<link rel="prev" href="'. get_site_url() .'/blog/page/' . $paged - 1 .'" />';
    	}
    	return $link;
    });

    You may refer to this guide on how to add filters to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how that goes. Looking forward to helping you.

    Jordan Dick
    Rank Math free

    You nailed it. Under reading > settings, there was no post page selected. Thank you!

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘Blog Pagination Next and Prev ( rel=next/rel=prev ) Not Showing in Source Code’ is closed to new replies.