Last active
July 18, 2023 01:34
-
-
Save mrkdevelopment/5df47150bc3d0905e463fe0fd94bcb9c to your computer and use it in GitHub Desktop.
Snippet to Edit a breadcrumb path inside Yoast SEO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
?> |
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
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
You can see details on how this snippet works to make a custom yoast breadcrumb path on my blog.