I need to rewrite all attachment urls by the following rule
This is the current urls for the attachments:
domain.de/?attachment_id=17806
This is how it should look like:
domain.de/bilder/image_meta_title
This is what i tried - the rule itself is working but the links don't work:
add_action('generate_rewrite_rules', 'attachment_rewrite_rule_14924');
//URL Rewrite Rule for attachments
function wpd_attachment_link( $link, $post_id ){
$post = get_post( $post_id );
$post = $post->post_title;
$post = str_replace(" ","-",$post);
return home_url( '/bilder/' . $post);
}
add_filter( 'attachment_link', 'wpd_attachment_link', 20, 2 );
Can anyone help me and tell what could be possibly wrong here? As i mentioned before, i get successfully the url rewritten but the url is broken then, it doesn't refer to the attached media.