How add rel=“no-follow” to wordpress paginate_link

2019-08-01 06:43发布

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 );
?>

1条回答
地球回转人心会变
2楼-- · 2019-08-01 06:55

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>'
查看更多
登录 后发表回答