Skip to content

Instantly share code, notes, and snippets.

@TimBHowe
Created July 31, 2023 14:29
Show Gist options
  • Save TimBHowe/1604b163230337a5d3a312f8e1c7599b to your computer and use it in GitHub Desktop.
Save TimBHowe/1604b163230337a5d3a312f8e1c7599b to your computer and use it in GitHub Desktop.
Add 'rel="next"' and 'rel="prev"' attribute to the next and previous links in the paginate_links function in WordPress.
<?php
/**
* Alter the pagination next and prev links to have rel.
*
* @param string $r HTML output.
* @param array $args An array of arguments. See paginate_links() for information on accepted arguments.
*
* @return sting - The HTML output of the pagination.
*/
function scaffolding_add_rel_pagination( $r, $args ) {
$r = str_replace( 'class="prev', 'rel="prev" class="prev', $r );
$r = str_replace( 'class="next', 'rel="next" class="next', $r );
return $r;
}
add_filter( 'paginate_links_output', 'scaffolding_add_rel_pagination', 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment