add class to anchor in next_post_link & previous_post_link
-
Hi,
I’ve seen this asked a number of times, but haven’t seen a solution that was straightforward enough for me to use.
I need to add a class to the anchor tag that’s returned by next_post_link and previous_post_link
While I appreciate people have suggested things like wrapping the php tag in another pair of tags like a span and classing that, or the fact that next_post_link allows you to place tags around the anchor, that is not a solution for this case.
What I am trying to do, can only be achieved with a class on the anchor. I’ve tried numerous other combinations of nesting classes on parent objects, and it doesn’t work.
I’ve achieved a similar outcome for the next_posts_link and previous_posts_link to navigate between category pagination by adding this to the functions.php file
add_filter('next_posts_link_attributes', 'posts_link_attributes'); add_filter('previous_posts_link_attributes', 'posts_link_attributes'); function posts_link_attributes(){ return 'class="internav"'; }
however I don’t know enough to know how that works, except that the return bit seems to add whatever you put in there to the output that next_posts_link spits out into the HTML
Could someone please give me a solution for dummies that i can just copy & paste into my functions.php, so that I can try to learn from seeing a working example?
Thanks.
- The topic ‘add class to anchor in next_post_link & previous_post_link’ is closed to new replies.