Iâm trying to remove the attachment slug from the attachment URL generated by wordpress. My current URL structure looks like:
www.site.com/category/folder/attachment/file
I made a function for that but the url output Iâm getting is www.site.com/folder/file, its missing the category. Any idea how I can fix that? Here is what I got so far:
function wpd_attachment_link( $link, $post_id ){
$post = get_post( $post_id );
$post_data = get_post($post->post_parent);
return home_url( single_cat_title('', false)."/".$post_data->post_name."/". $post->post_title );
}
add_filter( 'attachment_link', 'wpd_attachment_link', 20, 2 );
P.S: i know that can be done if i change the permalink structure from the main wordpress menu, but dont want to change the current permalink structure.
Try following code: