Skip to content

Instantly share code, notes, and snippets.

@oliwa
Last active December 5, 2018 07:09
Show Gist options
  • Select an option

  • Save oliwa/ca1db468473ffb9028135543c05b2378 to your computer and use it in GitHub Desktop.

Select an option

Save oliwa/ca1db468473ffb9028135543c05b2378 to your computer and use it in GitHub Desktop.
add a class to next/prev post and posts links
<?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