Hi Currently in our wordpress our default permalink structure is
abc.com/%postname%-%post_id%.html
But for specific category I want different permalink structure
Ex: for Photos Category i want url structure as
abc.com/%post_id%.html
Current i am using the following code But it is not working
add_filter( 'post_link', 'custom_permalink', 10, 3 );
function custom_permalink( $permalink, $post, $leavename ) {
// Get the categories for the post
$category = get_the_category($post->ID);
if ( !empty($category) && $category[0]->cat_name == "Photos" ) {
$permalink = home_url('/'.$post->ID .'.html' );
}
return $permalink;
}
But i am not getting different permalink structure for specific category posts. Please help me.
Posts must have a non-numeric slug because slug is an unique identifier.
So please use %post_id% in conjunction with other text. That will surely work.
The custom permalink url like abc.com/%post_id%.html for specific category post is not possible and the same topic is discussed on https://wordpress.org/support/topic/post_id-only-permalink-comes-with-date-and-death-links.