[英]WordPress - Yoast Disable specific page href link in breadcrumb trail, but don't remove text
Using Yoast to generate the breadcrumb trail, I can't figure out how to remove just the HREF attribute, so the breadcrumb is just text.使用 Yoast 生成面包屑轨迹,我无法弄清楚如何仅删除 HREF 属性,因此面包屑只是文本。 I'm using custom links to organize the site content.
我正在使用自定义链接来组织网站内容。 I put in blank pages so that the breadcrumb trail would render properly, but now of course I have a link to blank pages.
我放入了空白页面,以便正确呈现面包屑路径,但现在我当然有一个指向空白页面的链接。 I've considered putting an index/TOC on these pages, but it seems so pointless.
我考虑在这些页面上放置一个索引/目录,但这似乎毫无意义。
Here's the simplest code that I've found that disables link and text, but I can't find an example (that works) that removes just the link (href).这是我发现的禁用链接和文本的最简单代码,但我找不到仅删除链接(href)的示例(有效)。
add_filter( 'wpseo_breadcrumb_single_link' ,'wpseo_remove_breadcrumb_link', 10 ,2);
function wpseo_remove_breadcrumb_link( $link_output , $link ){
$text_to_remove = 'Products';
if( $link['text'] == $text_to_remove ) {
$link_output = '';
}
return $link_output;
}
You can try this:你可以试试这个:
add_filter( 'wpseo_breadcrumb_single_link' ,'wpseo_just_remove_breadcrumb_link', 10 ,2);
function wpseo_just_remove_breadcrumb_link( $link_output , $link ){
//In case you want to remove multiple links put those texts here in this array.
$text_to_remove = ['Products', 'Something else'];
if(in_array($link['text'] , $text_to_remove )) {
$link_output = str_replace('href="'.$link['url'].'"' , "" , $link_output);
return str_replace('data-wpel-link="internal"' , "" , $link_output);
}
return $link_output;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.