How add rel=”no-follow” to wordpress paginate_links()

Need help.
I want to add rel=”nofollow” tag to the pagination links that is shown in my website theme.
I am using this function to use pagination.

<?php
    $paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
    $pag_args1 = array(
        'format'  => '?paged1=%#%',
        'current' => $paged1,
        'total'   => $query1->max_num_pages,
        'prev_text'    => __('&laquo; Prev'),
        'next_text'    => __('Next &raquo;'),
        'add_args' => array( 'paged2' => $paged2 )
    );
    echo paginate_links( $pag_args1 );
?>

Related posts

Leave a Reply

1 comment

  1. WordPress does not expose any filters for modifying or adding HTML attributes to <a> tags generated by paginate_links. Fortunately the links returned by the function are fairly simply and standard, so string substitution should do the trick:

    $links = paginate_links($args);
    // $links is a string like '<a href="..">..</a> <a href="..">..</a>'
    $links = str_replace('<a ', '<a rel="nofollow" ', $links);
    // $links is now a string like '<a rel="nofollow" href="..">..</a> <a rel="nofollow" href="..">..</a>'