Custom Yoast Breadcrumbs URL

That’s an unusual setup – Yoast usually recognizes the right permalinks. You may want to consider changing the way you set up your custom post type, so that it has the desired names and URLs to begin with. You’re likely to have two different URLs that point to the same content, which is undesirable for SEO and sometimes confusing to end users.

However, to answer your original question, you can use another filter called wpseo_breadcrumb_links:

// Hook to the filter
add_filter('wpseo_breadcrumb_links', 'wpse_332125_breadcrumbs');
// $links are the current breadcrumbs
function wpse_332125_breadcrumbs($links) {
    // Use is_singular($post_type) to identify a single CPT
    // This assumes your CPT is called "project" - change it as needed
    if(is_singular('project')) {
        // The first item in $links ($links[0]) is Home, so skip it
        // The second item in $links is Projects - we want to change that
        $links[1] = array('text' => 'Case Studies', 'url' => '/case-studies/', 'allow_html' => 1);
    }
    // Even if we didn't change anything, always return the breadcrumbs
    return $links;
}

You’ll want to make sure to test everything thoroughly, to make sure both the original links and the breadcrumbs all work as expected. Hope this helps you and others, as it took me a long time to stumble on this almost-undocumented filter!

Leave a Comment