Skip to content

Instantly share code, notes, and snippets.

@gjportegies
Forked from theJasonJones/wp-seo-tweaks.php
Created February 16, 2026 15:39
Show Gist options
  • Select an option

  • Save gjportegies/02175465493d5ade73d16d11bf5b0855 to your computer and use it in GitHub Desktop.

Select an option

Save gjportegies/02175465493d5ade73d16d11bf5b0855 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment