I'd like to remove the product base from the yoast breadcrumbs on the signle product page
e.g. here
pbs.transparentwebdesigns.co.uk/p/bahco-244-fine-cut-saw-22-11-tpi/
the breadcrumb is:
Home » Products » Hand Tools » Hand Saws » BAHCO 244 FINE CUT SAW 22? 11 TPI
I want it to be:
Home » Hand Tools » Hand Saws » BAHCO 244 FINE CUT SAW 22? 11 TPI
How do I do this?
Dbranes answers:
Here are two (untested) ideas:
1) You might try the <em>wpseo_breadcrumb_output</em> filter:
add_filter( 'wpseo_breadcrumb_output', 'custom_wpseo_breadcrumb_output' );
function custom_wpseo_breadcrumb_output( $output ){
if( is_page() ){
$from = '<a href="">...</a>'; // EDIT this to your needs
$to = '';
$output = str_replace( $from, $to, $output );
}
return $output;
}
2) You could also try the <em>wpseo_breadcrumb_links</em> filter to remove items from the <em>$links</em> array.
To see what the array contains you could try:
add_filter( 'wpseo_breadcrumb_links', 'wpseo_breadcrumb_links' );
function custom_wpseo_breadcrumb_output( $links ){
if( is_page() ){
var_dump( $links );
// unset the right item here ...
}
return $links;
}
and use that info to unset the corresponding array item from <em>$links</em>.
willcm comments:
Hmmm, seems like this may work but I'm not great with code...
so in my case what do I need to put in my functions.php file to remove "Products"?
willcm comments:
Hmmm, seems like this may work but I'm not great with code...
so in my case what do I need to put in my functions.php file to remove "Products"?
Dbranes comments:
You could try version <strong>(1)</strong> with
$from = '<span typeof="v:Breadcrumb"><a href="http://pbs.transparentwebdesigns.co.uk/products/" rel="v:url" property="v:title">Products</a></span> »';
ps: you add the code snippets into your <em>functions.php</em> file in the current theme directory.
Dbranes comments:
If you go for method 2) you could try:
add_filter( 'wpseo_breadcrumb_links', 'custom_wpseo_breadcrumb_links' );
function custom_wpseo_breadcrumb_links( $links ){
if( is_page() ){
// print_r( $links );
unset( $links[1] ); // unset the second array item (starts from 0, 1, 2, ... )
}
return $links;
}
willcm comments:
I've tried both in functions.php and neither work...
willcm comments:
actually it did I just had to change the "if" statement:
add_filter( 'wpseo_breadcrumb_links', 'custom_wpseo_breadcrumb_links' );
function custom_wpseo_breadcrumb_links( $links ){
if( is_product() ){
// print_r( $links );
unset( $links[1] ); // unset the second array item (starts from 0, 1, 2, ... )
}
return $links;
}
willcm comments:
ok so this removes the link on the final product category - how do I get that back?
see here:
http://pbs.transparentwebdesigns.co.uk/p/bahco-244-fine-cut-saw-22-11-tpi/#tab-description
willcm comments:
This is the correct answer from Dbranes:
add_filter( 'wpseo_breadcrumb_output', 'custom_wpseo_breadcrumb_output' );
function custom_wpseo_breadcrumb_output( $output ){
if( is_product() ){
$from = '<span typeof="v:Breadcrumb"><a href="http://pbs.transparentwebdesigns.co.uk/products/" rel="v:url" property="v:title">Products</a></span> »';
$to = '';
$output = str_replace( $from, $to, $output );
}
return $output;
}
isp_charlie answers:
try this js man :
jQuery(function(){
jQuery("#breadcrumbs span").each(function(){
if(jQuery(this).text()=="Products"){jQuery(this).remove()}
})
})
willcm comments:
I'd prefer not to do this by js - thanks though