Set product page url with product id and not product name
-
I need to get in the url the product id and not the product name but it is not working
I tried to use the following code in functions but it returns 404 what could be?add_filter( ‘post_type_link’, ‘my_post_type_link’, 10, 2 );
function my_post_type_link( $post_link, $post = null ) {
if ( !empty($post) ) {
$post_type = get_post_type($post->ID);if($post_type == “product”) {
return str_replace(‘%post_id%’, $post->ID, $post_link);
} else {
return str_replace(‘%post_id%’, ”, $post_link);
}
}
}
- The topic ‘Set product page url with product id and not product name’ is closed to new replies.