移除WordPress首页


Remove WordPress front page rel next

有人知道如何删除默认的WordPress首页rel next并添加自定义rel next吗?下一级是错的。因为我在我的首页上使用分页。

<link rel='next' title='About Us' href='http://myweb/about-us' />

接下来我想更正我的rel。谁都可以帮我。

 <link rel='next' href='http://myweb/page/2' />
使用<<p> strong> add_action ,和 remove_action

推荐使用方法:
我不确定add_actionremove_action是正确的工具,但既然你愿意使用它们,你应该愿意使用add_filter -其中正确的工具。

你可以钩入两个过滤器:

add_filter( "previous_post_rel_link", 'remove_title_from_previous_link' );  
add_filter( "next_post_rel_link", 'remove_title_from_next_link' );  

然后,编写解析/删除title属性的函数:

function remove_title_from_previous_link($link) {
    // Write your code here to provide and return the correct link
    // Sample only below:   
    return '<a href="my_custom_url" title="Corrected Url" rel="previous">';
}
function remove_title_from_next_link($link) {
    // Write your code here to provide and return the correct link
    // Sample only below:   
    return '<a href="my_custom_url" title="Corrected Url" rel="next">';
}
编辑:


如果您确实必须使用add_actionremove_action,那么您需要像这样挂钩到此操作:

remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 999);

add_action('wp_head', 'my_custom_rel_link_function');

当然还有你的自定义函数:

function my_custom_rel_link_function() {
    // ... do your magic here ...
}

这只是首页

将下面的代码添加到header部分

// add custom link rel for home page
if(is_front_page()){
    $post_per_page = 1;
    $paged = (get_query_var('page')) ? get_query_var('page') : 1; 
    $published_posts = wp_count_posts()->publish;
    $prev_link  =   get_pagenum_link( $paged - 1 );
    $next_link  =   get_pagenum_link( $paged +1 );
    if( $paged >= 2 ){
        echo "<link rel='"prev'" href='"".$prev_link."'"/>"."'n";
    }
    if( $published_posts > ( $post_per_page * $paged ) ){
        echo "<link rel='"next'" href='"".$next_link."'"/>"."'n";
    }
}

解决方案如下:

删除rel="next" &rel="prev" from custom post types and pages.

function.php中添加以下代码

add_filter( 'wpseo_next_rel_link', '__return_false' );
add_filter( 'wpseo_prev_rel_link', '__return_false' );