Last active
November 20, 2024 08:50
-
-
Save amboutwe/ea0791e184668a5c7bd7bbe357c598e9 to your computer and use it in GitHub Desktop.
Multiple examples of how to customize the Yoast SEO breadcrumbs
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 | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* Overwrite Rank Math breadcrumb shortcode with Yoast breadcrumbs | |
* Credit: Yoast team | |
* Last Tested: April 10, 2023 using Yoast SEO 20.4 on WordPress 6.2 | |
* Rank Math must be inactive to overwrite the shortcode | |
*/ | |
add_action('init', 'overwrite_rankmath_bc_shortcode_with_Yoast'); | |
function overwrite_rankmath_bc_shortcode_with_Yoast() { | |
add_shortcode('rank_math_breadcrumb', 'my_custom_wpseo_breadcrumb'); | |
} | |
function my_custom_wpseo_breadcrumb() { | |
return do_shortcode('[wpseo_breadcrumb]'); | |
} |
@yes-or-not is it possible to put the following before unset($links[0]);
?
echo '<pre>';
print_r($links);
die;
If possible put this and see what output returns.
where should I put this commend?
Hi, thanks for these.
Do you know how to add 2 links to breadcrumbs´s path instead just one?
Home » Link 1 » Link 2 » Single post
And how to remove Home link with Yoast Seo?
Link 1 » Link 2 » Single post
Thank you!
This is not the proper place to request support. Please check out our extensive help section or visit the free support forum. If you require further support, upgrading to our premium version provides you with access to our support team.
for people who need to update the url for the categories
// EDITING CATEGORY URL
add_filter( 'wpseo_breadcrumb_links', 'custom_breadcrumb_links' );
function custom_breadcrumb_links( $links ) {
// Loop through the breadcrumb links array
foreach ( $links as $index => $link ) {
// Check if this is the CATEGORY
if ( $link['text'] === 'Blog' ) {
// Set the custom URL for breadcrumb
$custom_url = 'https://example.com/blog';
// Modify the link array with the custom URL
$links[$index]['url'] = $custom_url;
} elseif ( $link['text'] === 'Installers' ) {
// Set the custom URL for breadcrumb
$custom_url = 'https://example.com/installer';
// Modify the link array with the custom URL
$links[$index]['url'] = $custom_url;
} elseif( $link['text'] === 'Competitors' ) {
// Set the custom URL for breadcrumb
$custom_url = 'https://example.com/competitor';
// Modify the link array with the custom URL
$links[$index]['url'] = $custom_url;
}
}
return $links;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry but I can't give you login data.
Here is code from "functions" file:
I changed only text "shop" into "sklep".