How to add sku at the end of slug
-
Hi,
I want to add woocommerce sku at the end of product url and also limit the slug words to 5 words and i use this code but when i add bigger title it limit it to 5 words but it did not add the sku at the end. I also tried regenerate option in tools.
function pm_limit_slugs_length($uri) {
$max_words = 5; // If any part of URI contains more than 5 words, the slug will be limited to first 5 words
$new_title = ”;
$slugs = explode(‘/’, $uri);for($i=0, $count = count($slugs); $i < $count; $i++) {
$slug = $slugs[$i];
$words = explode(‘-‘, $slug);$new_title .= “/”;
if(count($words) > $max_words) {
$new_title .= implode(“-“, array_slice($words, 0, $max_words));
} else {
$new_title .= $slug;
}
}// Remove trailing slashes
$new_title = trim($new_title, “/”);return $new_title;
}
add_filter(‘permalink_manager_filter_default_post_uri’, ‘pm_limit_slugs_length’, 99);
add_filter(‘permalink_manager_filter_default_term_uri’, ‘pm_limit_slugs_length’, 99);
- The topic ‘How to add sku at the end of slug’ is closed to new replies.