-
-
Save amboutwe/ea0791e184668a5c7bd7bbe357c598e9 to your computer and use it in GitHub Desktop.
<?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]'); | |
} |
Hi
I have shop created in WP in subpage "Shop" not on main page. How to change link from 'home' in breadcrumbs to "shop page" ?
To be clear: there is page in domain "www.mydomain.xx" and shop on page "www.mydomain.xx/shop" and when I am on page with shop or products I want to have breadcrumbs linking to main shop page so to "www.mydomain.xx/shop" not like it is now to www.mydomain.xx How to do this? I want to have home page=shop page not main domain page.....
@yes-or-not I think you can do it by go to Setting > Reading > Set shop page as a home page if you want to set shop page as a main landing page.
Hope this will work for you.
Thank you. Regards,
Vivek
vivekkotadiya
Probably yes but I want to have 'shop' as main only if I am on sub-pages of shop and products. There are many pages not connected with shop....
@yes-or-not Is it possible to share your URL for explain how you want you URL structure for main page as well as sub pages.
sure but it isn't going to be easy for you sice it is not in english.
www.tomauto.pl and www.tomauto.pl/sklep
No issues I will catch it. Now let me know which URL should be your main landing page URL?
All related with shop should go to tomauto.pl/sklep (main shop page and categories and products) Rest should go to main domain page.
Have you used any SEO plugin...? LIke yoast or All in one SEO? Or how you have set breadcrumb on your site?
No need to change anything here. There is one small filter hook for that.
add_filter( 'wpseo_breadcrumb_links', 'dgtlnk_breadcrumbs' );
function dgtlnk_breadcrumbs( $links ) {
global $post;
if ( is_woocoomerce() ) {
$breadcrumb[] = array(
'url' => woocoommerce_shop_page(),
'text' => 'Shop',
);
array_splice( $links, 1, -2, $breadcrumb );
}
return $links;
}
This will work I think. In my case there was issue with product category page.
Is there any mistake in the code?
I put this code to functions.php in my theme but I got critical error when refresh my site.
add_filter( 'wpseo_breadcrumb_links', 'fs_breadcrumbs' );
function fs_breadcrumbs( $links ) {
global $post;
if ( is_woocommerce() ) {
$breadcrumb[] = array(
'url' => wc_get_page_permalink( 'shop' ),
'text' => 'Shop',
);
array_splice( $links, 1, -2, $breadcrumb );
}
return $links;
}
Try this, this will not break. Tested snippet.
Thank you. Regards,
Vivek
Okay so for these pages you want to remove first main page URL right...? If so then try with this updated code:
add_filter( 'wpseo_breadcrumb_links', 'fs_breadcrumbs' );
function fs_breadcrumbs( $links ) {
global $post;
if ( is_woocommerce() ) {
$breadcrumb[] = array(
'url' => wc_get_page_permalink( 'shop' ),
'text' => 'Shop',
);
array_splice( $links, 1, -2, $breadcrumb );
unset($links[0]);
}
return $links;
}
Hope this worked!
Thank you. Regards,
Vivek
w: https://flexsolutions.co.in/
no, any results in breakcrums. Still the same look. Maybe should I change something in Yoast SOE plugin? I have marked checkbox next to enable breadcrumbs in choosen theme. What else can be wrong ?
@yes-or-not Sorry to missed to reply here. Is it possible to share your admin login or staging enviornment so I can look into it and help you to fix it.
Sorry but I can't give you login data.
Here is code from "functions" file:
<?php
/**
*
* This program is a free software; you can use it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along with this program; if not, write
* to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
if ( !defined( 'CZR_MIN_PHP_VERSION' ) ) define ( 'CZR_MIN_PHP_VERSION', 5.3 );
if ( !defined( 'CZR_MIN_WP_VERSION' ) ) define ( 'CZR_MIN_WP_VERSION', 4.5 );
if ( version_compare( phpversion(), CZR_MIN_PHP_VERSION, '<' ) ) {
add_action( 'admin_notices' , 'czr_fn_display_min_php_message' );
return;
}
global $wp_version;
if ( version_compare( $wp_version, CZR_MIN_WP_VERSION, '<' ) ) {
add_action( 'admin_notices' , 'czr_fn_display_min_wp_message' );
return;
}
function czr_fn_display_min_php_message() {
czr_fn_display_min_requirement_notice( __( 'PHP', 'customizr' ), CZR_MIN_PHP_VERSION );
}
function czr_fn_display_min_wp_message() {
czr_fn_display_min_requirement_notice( __( 'WordPress', 'customizr' ), CZR_MIN_WP_VERSION );
}
function czr_fn_display_min_requirement_notice( $requires_what, $requires_what_version ) {
$theme = wp_get_theme()->Name;
printf( '<div class="error"><p>%1$s</p></div>',
sprintf( __( 'The <strong>%1$s</strong> theme requires at least %2$s version %3$s', 'customizr' ),
$theme,
$requires_what,
$requires_what_version
)
);
}
/**
* This is where Customizr starts. This file defines and loads the theme's components :
* => Constants : CUSTOMIZR_VER, TC_BASE, TC_BASE_CHILD, TC_BASE_URL, TC_BASE_URL_CHILD, THEMENAME, CZR_WEBSITE
* => Default filtered values : images sizes, skins, featured pages, social networks, widgets, post list layout
* => Text Domain
* => Theme supports : editor style, automatic-feed-links, post formats, navigation menu, post-thumbnails, retina support
* => Plugins compatibility : JetPack, bbPress, qTranslate, WooCommerce and more to come
* => Default filtered options for the customizer
* => Customizr theme's hooks API : front end components are rendered with action and filter hooks
*
* The method CZR__::czr_fn__() loads the php files and instantiates all theme's classes.
* All classes files (except the class__.php file which loads the other) are named with the following convention : class-[group]-[class_name].php
*
* The theme is entirely built on an extensible filter and action hooks API, which makes customizations easy and safe, without ever needing to modify the core structure.
* Customizr's code acts like a collection of plugins that can be enabled, disabled or extended.
*
* If you're not familiar with the WordPress hooks concept, you might want to read those guides :
* http://docs.presscustomizr.com/article/26-wordpress-actions-filters-and-hooks-a-guide-for-non-developers
* https://codex.wordpress.org/Plugin_API
*/
//Fire Customizr
require_once( get_template_directory() . '/core/init-base.php' );
/**
* THE BEST AND SAFEST WAY TO EXTEND THE CUSTOMIZR THEME WITH YOUR OWN CUSTOM CODE IS TO CREATE A CHILD THEME.
* You can add code here but it will be lost on upgrade. If you use a child theme, you are safe!
*
* Don't know what a child theme is ? Then you really want to spend 5 minutes learning how to use child themes in WordPress, you won't regret it :) !
* https://codex.wordpress.org/Child_Themes
*
* More informations about how to create a child theme with Customizr : http://docs.presscustomizr.com/article/24-creating-a-child-theme-for-customizr/
* A good starting point to customize the Customizr theme : http://docs.presscustomizr.com/article/35-how-to-customize-the-customizr-wordpress-theme/
*/
/**
* Filter payment gateways
*/
function my_custom_available_payment_gateways( $gateways ) {
$chosen_shipping_rates = ( isset( WC()->session ) ) ? WC()->session->get( 'chosen_shipping_methods' ) : array();
if ( in_array( 'flat_rate:4', $chosen_shipping_rates ) ) :
unset( $gateways['bacs'],$gateways['wppay'],$gateways['wppay-blik-zero'], $gateways['wppay-card']);
elseif ( in_array( 'flat_rate:3', $chosen_shipping_rates ) ) :
unset( $gateways['cod'] );
elseif ( in_array( 'flat_rate:5', $chosen_shipping_rates ) ) :
unset( $gateways['cod'] );
elseif ( in_array( 'local_pickup:2', $chosen_shipping_rates ) ) :
unset( $gateways['bacs'] );
endif;
return $gateways;
}
add_filter( 'wpseo_breadcrumb_links', 'fs_breadcrumbs' );
function fs_breadcrumbs( $links ) {
global $post;
if ( is_woocommerce() ) {
$breadcrumb[] = array(
'url' => wc_get_page_permalink( 'sklep' ),
'text' => 'Sklep',
);
array_splice( $links, 1, -2, $breadcrumb );
unset($links[0]);
}
return $links;
}
I changed only text "shop" into "sklep".
@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;
}
Why this filter hook is not worked with woocommerce product category?
Here is my code: