0

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!

3

3 Answers 3

1

You can do something like this:-

<div class="YOUR-CLASS">
<?php posts_nav_link(' — ', __('« go back'), __('keep looking »')); ?>
</div>

See Documents Here.

Hope this will help you..

Sign up to request clarification or add additional context in comments.

Comments

0

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 */
}

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.