Skip to content

Instantly share code, notes, and snippets.

@theJasonJones
Last active November 16, 2023 20:49
Show Gist options
  • Save theJasonJones/ee4ab51ce1bc7925bed2cd49473b3812 to your computer and use it in GitHub Desktop.
Save theJasonJones/ee4ab51ce1bc7925bed2cd49473b3812 to your computer and use it in GitHub Desktop.
Had to a few tweaks to the WP-SEO breadcrumbs. This is what I did.
<?php
// Remove the last link in breadcrumbs
// WHY? Because it an span tag that contains the title of the page
// But you're already on the page, so what's the point?
add_filter( 'wpseo_breadcrumb_links', 'jj_wpseo_breadcrumb_links' );
function jj_wpseo_breadcrumb_links( $links ) {
//pk_print( sizeof($links) );
if( sizeof($links) > 1 ){
array_pop($links);
}
return $links;
}
// Add link to the last item in the breadcrumbs
// WHY? Because, by default, WP-SEO doesn't include the link on the last item
// Since we removed in the function above, we need to add the link back in.
add_filter( 'wpseo_breadcrumb_single_link', 'jj_link_to_last_crumb' , 10, 2);
function jj_link_to_last_crumb( $output, $crumb){
$output = '<a property="v:title" rel="v:url" href="'. $crumb['url']. '" >';
$output.= $crumb['text'];
$output.= '</a>';
return $output;
}
// Add a page to the breadcrumbs of custom taxonomies or post types.
add_filter( 'wpseo_breadcrumb_links', 'my_wpseo_breadcrumb_links' );
function my_wpseo_breadcrumb_links( $links ) {
global $post;
// Single pages
if( $post->post_type == 'custom-post-type' ){
// Add cart page link
array_splice($links, 1, 0, array(
array(
'text' => get_the_title(34),
'url' => get_the_permalink(34)
)
));
return $links;
}
}
@mstudioIL
Copy link

Thanks for code to make the last item as link.
Do you how the change the schema to be with OL LI?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment