如何添加rel ="no-follow"? WordPress的paginate_links() [英] How add rel="no-follow" to wordpress paginate_links()

查看:73
本文介绍了如何添加rel ="no-follow"? WordPress的paginate_links()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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>'

这篇关于如何添加rel ="no-follow"? WordPress的paginate_links()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆