How can I add a CSS Class to the previous_post_link
output or just get the URL and create the HTML markup myself
Leave a Reply
You must be logged in to post a comment.
How can I add a CSS Class to the previous_post_link
output or just get the URL and create the HTML markup myself
You must be logged in to post a comment.
You can use the more native function that is “below” the
previous_/next_post_link();
:There are filters for previous_post_link and next_post_link functions which works in a different way from previous_posts_link_attributes and next_posts_link_attributes, I am not sure why this is not documented on the wordpress website.
You could put an element around the function call and style it that way. Like this:
then control the link in the css.
Just a little addition the problem with the hook below is that they are in plural forms and your question implies “you want to style them in singular form”.
Although they work perfectly but, these are the links that are displayed at the bottom of the post listings, not the ones at the bottom of individual posts. Logic says we should be able to duplicate this code with the singular forms (ânext_post_linkâ and âprevious_post_linkâ) and it will work. Unfortunately thatâs not the case.
Well since the filters for the singular next and previous links are applied differently see this
The code below should work for singular links. Put them in your function.php file
The above code is tested and works.
However you can workaround this with out using the function.php
is to class an LI around each link:
This code is not tested and notice the plurality.
Try to following way–
All very good thought the simplest way I found was to add a div in the functions.php file that wraps the links. I named mine class=”plinks”
then in your css file just write a new class for
Call it into any of your theme template pages using
This code will check if the $previous_post_obj and $next_post_obj variables are empty before generating the “previous” and “next” buttons, respectively. If either variable is empty, the corresponding button will not be displayed.