Are you looking for a way to add custom class to next and previous post_link
? We have created a quick code snippet that you can use to add class to next and previous post_link
in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
function add_class_next_post_link($html){ $html = str_replace('<a','<a class="next"',$html); return $html; } add_filter('next_post_link','add_class_next_post_link',10,1); function add_class_previous_post_link($html){ $html = str_replace('<a','<a class="prev"',$html); return $html; } add_filter('previous_post_link','add_class_previous_post_link',10,1);
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 27 best WordPress business themes for your website and 15 best content marketing tools and plugins for WordPress.
It’s really helpful, Excellent job.
wow, that’s cool! thanks man!
Cool glad to see you like the snippet