Swapping next/prev link attributes for single post navigation?
-
Hi!
I have a simple child theme where I’ve overridden a method to format posts/pages navigation links.It contains the following code for the single posts:
<?php if ( is_single() ) : // navigation links for single posts ?> <?php next_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'wp386' ) . '</span> %title' ); ?> <?php previous_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'wp386' ) . '</span>' ); ?>
The problem here is that the
previous_post_link()
inserts a value ofrel="prev"
(obviously) – while I would like it to insert arel="next"
instead, even if that seems counter-intuitive.Is there a simple way to change this using filters or some basic logic? I’m not very skilled with PHP but know my way around modifying existing code if needed. I’ve tried reading some of the docs but didn’t get any wiser unfortunately.
For instance, I managed to add rel links to the page/category pagination links on the main pages using the following relatively simple filter:
// Add rel attributes to next/previous links add_filter('next_posts_link_attributes', function(){return 'rel="next"';}); add_filter('previous_posts_link_attributes', function(){return 'rel="prev"';});
But for single posts I’m struggling to find a *simple* solution without having to write my own function(s) or overriding system functions. Apparently there is no filter for
next_post_link_attributes
?One of the reasons I’d like *previous* posts to have the
rel="next"
attribute is for working with the Vivaldi browser’s “Fast Forward” feature which looks for these kinds of attributes.
- The topic ‘Swapping next/prev link attributes for single post navigation?’ is closed to new replies.