Last active
December 5, 2018 07:09
-
-
Save oliwa/ca1db468473ffb9028135543c05b2378 to your computer and use it in GitHub Desktop.
add a class to next/prev post and posts links
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Add class to links generated by next_posts_link and previous_posts_link, | |
| // see https://css-tricks.com/snippets/wordpress/add-class-to-links-generated-by-next_posts_link-and-previous_posts_link/ | |
| add_filter('next_posts_link_attributes', 'posts_link_attributes'); | |
| add_filter('previous_posts_link_attributes', 'posts_link_attributes'); | |
| function posts_link_attributes() { | |
| return 'class="button"'; | |
| } | |
| // Add class to links generated by next_post_link and previous_post_link, | |
| // see http://wordpress.stackexchange.com/questions/17218/how-to-add-css-class-to-previous-post-link-or-get-previous-next-post-link-url | |
| function posts_link_next_class($format){ | |
| $format = str_replace('href=', 'class="button" href=', $format); | |
| return $format; | |
| } | |
| add_filter('next_post_link', 'posts_link_next_class'); | |
| function posts_link_prev_class($format) { | |
| $format = str_replace('href=', 'class="button" href=', $format); | |
| return $format; | |
| } | |
| add_filter('previous_post_link', 'posts_link_prev_class'); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment