| 1 |
<?php |
| 2 |
/** |
| 3 |
* Yoast Support |
| 4 |
* |
| 5 |
* Created Date: Wednesday October 12th 2022 |
| 6 |
* Author: Michael Bourne |
| 7 |
* ----- |
| 8 |
* Last Modified: Wednesday, February 11th 2026, 8:28:22 pm |
| 9 |
* Modified By: Michael Bourne |
| 10 |
* ----- |
| 11 |
* Copyright (c) 2022 URSA6 |
| 12 |
* |
| 13 |
* @package wp-commerce7 |
| 14 |
* @author Michael Bourne |
| 15 |
* @license GPL3 |
| 16 |
* @link https://ursa6.com |
| 17 |
* @since 1.3.3 |
| 18 |
*/ |
| 19 |
|
| 20 |
if ( ! defined( 'ABSPATH' ) ) { |
| 21 |
exit; |
| 22 |
} |
| 23 |
|
| 24 |
add_filter( |
| 25 |
'wpseo_canonical', |
| 26 |
function( $canonical_url ) { |
| 27 |
|
| 28 |
$options = get_option( 'c7wp_settings' ); |
| 29 |
|
| 30 |
// If the user has not set custom routes, use the defaults. |
| 31 |
if ( ! isset( $options['c7wp_frontend_routes'] ) || ! is_array( $options['c7wp_frontend_routes'] ) ) { |
| 32 |
$product_route = 'product'; |
| 33 |
$collection_route = 'collection'; |
| 34 |
} else { |
| 35 |
$product_route = $options['c7wp_frontend_routes']['product']; |
| 36 |
$collection_route = $options['c7wp_frontend_routes']['collection']; |
| 37 |
} |
| 38 |
|
| 39 |
// If the current page is a product or collection page, return false to disable canonical URL. |
| 40 |
if ( is_page( array( $product_route, $collection_route ) ) ) { |
| 41 |
return false; |
| 42 |
} |
| 43 |
|
| 44 |
return $canonical_url; |
| 45 |
} |
| 46 |
); |
| 47 |
|