Site icon CodeRevolution Knowledge Base

Automatically add classes to links generated by next_posts_link and previous_posts_link – CodeRevolution

By default, the next_posts_link() and previous_posts_link() are generated with no custom class. If you need one for your CSS styling or anything else, here’s a pretty simple way to add the needed class by using a hook.

Paste the following code in your 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="myclass"'; } 

Thanks to CSS Tricks for the function!

Exit mobile version