Created
June 27, 2018 16:37
-
-
Save samikeijonen/c34115a684035f696124384f846ad648 to your computer and use it in GitHub Desktop.
Filter pagination markup. And some wp_link_pages_link.
This file contains 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_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