The problem is that previous/next_post_link() does not have a filter, so you can’t add something to functions.php to alter the output.
Also, there is no option to return the link rather than echoing it, so there is no straightforward way to assign the output to a variable.
The only way that I know to do this is to replace the call to previous/next_post_link with code to capture the output by buffering and then alter it before echoing it.
In other words, you would need to edit the template file and replace this, or similar depending on your theme:
previous_post_link( '%link', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'twentyten' ) . '</span> %title',true );
ob_start(); previous_post_link( '%link', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'twentyten' ) . '</span> %title',false ); $link = ob_get_clean(); echo str_replace('<a ','<a class="myclass" ', $link);
Thanks for the response. Strangely enough, after pulling my hair out on dozens of combinations, and a night’s sleep, it turned out that I was able to find a very specific nesting order in the CSS that Opera would render – which was the reason for the whole problem in the first place.
Thanks for posting a solution – hopefully it’ll help other people. One question though – all the references to twentyten – does that require you have the functions file from twentyten in your theme? I generally like to build themes from scratch without anyone else’s functions included, just so I can know every deviation from core is one I put in manually.
For anyone else curious, the reference to the twentyten theme is a translation/localization function. If you are making your own theme, you would change “twentyten” to be your theme’s name — just tells it where to look for translation files.
- The topic ‘add class to anchor in next_post_link & previous_post_link’ is closed to new replies.