Skip to content

Instantly share code, notes, and snippets.

@generatepress
Created January 27, 2016 07:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save generatepress/79a3b6e8493e09ab1aae to your computer and use it in GitHub Desktop.
Save generatepress/79a3b6e8493e09ab1aae to your computer and use it in GitHub Desktop.
Add nofollow attribute to GeneratePress pagination
if ( ! function_exists( 'generate_paging_nav' ) ) :
function generate_paging_nav() {
// Don't print empty markup if there's only one page.
if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
return;
}
$paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
$pagenum_link = html_entity_decode( get_pagenum_link() );
$query_args = array();
$url_parts = explode( '?', $pagenum_link );
if ( isset( $url_parts[1] ) ) {
wp_parse_str( $url_parts[1], $query_args );
}
$pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
$pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
$format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
$format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';
// Set up paginated links.
$links = paginate_links( array(
'base' => $pagenum_link,
'format' => $format,
'total' => $GLOBALS['wp_query']->max_num_pages,
'current' => $paged,
'mid_size' => apply_filters( 'generate_pagination_mid_size', 1 ),
'add_args' => array_map( 'urlencode', $query_args ),
'prev_text' => __( '&larr; Previous', 'generate' ),
'next_text' => __( 'Next &rarr;', 'generate' ),
) );
$links = str_replace('<a ', '<a rel="nofollow" ', $links);
if ( $links ) :
echo $links;
endif;
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment