Skip to content

Instantly share code, notes, and snippets.

@samikeijonen
Created June 27, 2018 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samikeijonen/c34115a684035f696124384f846ad648 to your computer and use it in GitHub Desktop.
Save samikeijonen/c34115a684035f696124384f846ad648 to your computer and use it in GitHub Desktop.
Filter pagination markup. And some wp_link_pages_link.
<?php
add_filter( 'navigation_markup_template', function( $template, $class ) {
// Set custom modifier classes.
$class = 'pagination' === $class ? 'posts' : 'comments';
// Modified template with custom classes.
$template = '
<nav class="pagination pagination--' . $class . '" role="navigation">
<h2 class="screen-reader-text">%2$s</h2>
<div class="pagination__items">%3$s</div>
</nav>';
return $template;
}, 10, 2 );
/**
* Wraps page "links" that aren't actually links (just text) with `<span class="page-numbers">` so that they
* can also be styled. This makes `wp_link_pages()` consistent with the output of `paginate_links()`.
*
* @param string $link Link in wp_link_pages().
* @return string
*/
add_filter( 'wp_link_pages_link', function( $link ) {
return 0 !== strpos( $link, '<a' ) ? "<span class='pagination__item'>{$link}</span>" : $link;
}, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment