1

需要帮忙。
我想将 rel="nofollow" 标签添加到我的网站主题中显示的分页链接。
我正在使用此功能来使用分页。

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

1 回答 1

5

Wordpress 不公开任何过滤器来修改或添加 HTML 属性到<a>paginate_links. 幸运的是,该函数返回的链接非常简单和标准,因此字符串替换应该可以解决问题:

$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>'
于 2012-12-13T05:37:48.660 回答