I am wondering how to add a css class to this part of the code which is linking to the older posts on a blog.
<?php posts_nav_link(' — ', __('« go back'), __('keep looking »')); ?>
Thanks!
I am wondering how to add a css class to this part of the code which is linking to the older posts on a blog.
<?php posts_nav_link(' — ', __('« go back'), __('keep looking »')); ?>
Thanks!
You can do something like this:-
<div class="YOUR-CLASS">
<?php posts_nav_link(' — ', __('« go back'), __('keep looking »')); ?>
</div>
Hope this will help you..
There's a jQuery way for issues like this, when you're not able to add classes to WP functions. Just add the class via jQuery:
HTML
<div class="navigation">
<?php posts_nav_link(' — ', __('« go back'), __('keep looking »')); ?>
</div>
jQuery
$(function() {
$('.navigation a:first-child').addClass('your-class');
});
This will add a class to the first link in the div.
There's a CSS way as well without adding a class but properties:
.navigation a:first-child {
/* your properties here */
}
If you want to add css classes to the <a> tag generated by posts_nav_link() function, another way of doing it is using these hooks in your functions.php file
add_filter('next_posts_link_attributes', 'posts_nav_attributes');
add_filter('previous_posts_link_attributes', 'posts_nav_attributes');
function posts_nav_attributes() {
return 'class="btn btn-primary text-uppercase"';
}
Read more of these here: https://developer.wordpress.org/reference/hooks/next_posts_link_attributes https://developer.wordpress.org/reference/hooks/previous_posts_link_attributes