Created
May 17, 2024 13:31
-
-
Save mio31337/36ec8fda102406da6a5a48b37b4ae32b to your computer and use it in GitHub Desktop.
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 this code to your theme's function.php file | |
/** | |
* Remove /kategorija/ from Yoast SEO canonical meta data | |
*/ | |
function custom_yoast_canonical( $canonical ) { | |
if ( is_product_category() ) { | |
$category = get_queried_object(); | |
$canonical = str_replace("kategorija/", "", get_term_link( $category, 'product_cat' )); | |
} | |
return $canonical; | |
} | |
add_filter( 'wpseo_canonical', 'custom_yoast_canonical' ); | |
/** | |
* Remove /kateogrija/ from Yoast SEO prev and next rel meta data | |
*/ | |
function custom_wpseo_prev_rel_link( $link ) { | |
if ( is_product_category() ) { | |
global $wp_query; | |
$queried_object = $wp_query->get_queried_object(); | |
if ( isset( $queried_object->slug ) ) { | |
$link = str_replace( '/kategorija/', '/', $link ); | |
} | |
} | |
return $link; | |
} | |
add_filter( 'wpseo_next_rel_link', 'custom_wpseo_prev_rel_link' ); | |
add_filter( 'wpseo_prev_rel_link', 'custom_wpseo_prev_rel_link' ); | |
/** | |
* Remove /kateogrija/ from Yoast SEO opengraph URL meta data | |
*/ | |
function custom_wpseo_opengraph_url( $url ) { | |
if ( is_product_category() ) { | |
global $wp_query; | |
$queried_object = $wp_query->get_queried_object(); | |
if ( isset( $queried_object->slug ) ) { | |
$url = str_replace( '/kategorija/', '/', $url ); | |
} | |
} | |
return $url; | |
} | |
add_filter( 'wpseo_opengraph_url', 'custom_wpseo_opengraph_url' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment