Php 删除WordPress首页rel next
任何人都知道如何删除默认的WordPress首页rel next和添加自定义rel next。 下面的rel next是错误的。因为我在头版使用分页Php 删除WordPress首页rel next,php,wordpress,Php,Wordpress,任何人都知道如何删除默认的WordPress首页rel next和添加自定义rel next。 下面的rel next是错误的。因为我在头版使用分页 <link rel='next' title='About Us' href='http://myweb/about-us' /> 下一步我想纠正我的错误。任何人都可以帮助我 <link rel='next' href='http://myweb/page/2' /> 使用添加操作和删除操作推荐方法: 我不确定
<link rel='next' title='About Us' href='http://myweb/about-us' />
下一步我想纠正我的错误。任何人都可以帮助我
<link rel='next' href='http://myweb/page/2' />
使用添加操作和删除操作推荐方法:
我不确定
add\u action
和remove\u action
是否是正确的工具,但既然您愿意使用它们,您应该愿意使用-哪个是正确的工具
您可以挂接两个过滤器:
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_action('wp_head', 'my_custom_rel_link_function');
当然还有您的自定义函数:
function my_custom_rel_link_function() {
// ... do your magic here ...
}
这仅限于头版 将以下代码添加到标题部分
// 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
如果(是首页()){
$post_/页=1;
$paged=(获取查询变量('page'))?获取查询变量('page'):1;
$published_posts=wp_count_posts()->publish;
$prev_link=get_pagenum_link($paged-1);
$next\u link=get\u pagenum\u link($paged+1);
如果($paged>=2){
回显“.”“\n”;
}
如果($published_posts>($post_/页*$paged)){
回显“.”“\n”;
}
}
下面的解决方案:
这将从自定义帖子类型和页面中删除rel=“next”
&rel=“prev”
在function.php中添加以下代码
add_filter( 'wpseo_next_rel_link', '__return_false' );
add_filter( 'wpseo_prev_rel_link', '__return_false' );
从哪里来?航行内容?边栏?。。。具体点。非常感谢你的回复。但这不是头版的工作。谢谢。我就这样改变。移除行动(‘wp_头’、‘相邻_柱’、‘相关链接’、‘wp_头’、10、0);
add_filter( 'wpseo_next_rel_link', '__return_false' );
add_filter( 'wpseo_prev_rel_link', '__return_false' );