Skip to content

Instantly share code, notes, and snippets.

@mrkdevelopment
Last active July 18, 2023 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrkdevelopment/5df47150bc3d0905e463fe0fd94bcb9c to your computer and use it in GitHub Desktop.
Save mrkdevelopment/5df47150bc3d0905e463fe0fd94bcb9c to your computer and use it in GitHub Desktop.
Snippet to Edit a breadcrumb path inside Yoast SEO
<?php
add_filter( 'wpseo_breadcrumb_links', 'fix_care_plan_bc_path' );
/**
* Custom breadcrumb paths using Yoast SEO to fix care plan breadcrumb paths.
*
* @param [array] $links default param.
* @return [array] $links edited links path.
*/
function fix_care_plan_bc_path( $links ) {
global $post;
if ( is_singular( 'cpplugins' ) || is_post_type_archive( 'cpplugins' ) ) {
$breadcrumb[] = array(
'url' => get_permalink( 25105 ),
'text' => 'Care Plans',
);
array_splice( $links, 1, -2, $breadcrumb );
}
return $links;
}
?>
@mrkdevelopment
Copy link
Author

You can see details on how this snippet works to make a custom yoast breadcrumb path on my blog.

@jcraighunter
Copy link

Thanks for providing this! I'm a novice at PHP, so this may seem like a ridiculous question. But if you can help, I would appreciate it:
What would I need to do to this code to add more than one link in the breadcrumb path? For example, you currently have it so it would appear: Home>Care Plans>Post
What if I needed it to be something like: Home>Additional Page>Care Plans>Post

@mrkdevelopment
Copy link
Author

Just add another one into the breadcrumbs[] array.

Did you read over the article? It explains what the array is along with a video.

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