在wp includes \\ link模板中。php定义分页的函数是:
/**
* Retrieves the previous posts page link.
*
* @since 2.7.0
*
* @global int $paged
*
* @param string $label Optional. Previous page link text.
* @return string|void HTML-formatted previous page link.
*/
function get_previous_posts_link( $label = null ) {
global $paged;
if ( null === $label )
$label = __( \'« Previous Page\' );
if ( !is_single() && $paged > 1 ) {
/**
* Filters the anchor tag attributes for the previous posts page link.
*
* @since 2.7.0
*
* @param string $attributes Attributes for the anchor tag.
*/
$attr = apply_filters( \'previous_posts_link_attributes\', \'\' );
return \'<a href="\' . previous_posts( false ) . "\\" $attr>". preg_replace( \'/&([^#])(?![a-z]{1,8};)/i\', \'&$1\', $label ) .\'</a>\';
}
}
我试图在我的主题函数中定义。php以下代码:
function previous_posts_link_callback() {
$res = \'rel="prev"\';
return $res;
}
add_filter( \'previous_posts_link_attributes\', \'previous_posts_link_callback\', 10, 3 );
为什么不起作用?
最合适的回答,由SO网友:Jacob Peattie 整理而成
尝试删除, 3
. 前面的\\u posts\\u link\\u attributes过滤器没有任何其他参数,因此这应该是1
, 或者根本不设置(1
是默认设置)。
add_filter( \'previous_posts_link_attributes\', \'previous_posts_link_callback\', 10 );