Replies: 0
Hello,
I have added this function in order to rewrite the permalink structure of my attachments :
add_filter( 'attachment_link', 'wpd_attachment_link', 20, 2 );
function wpd_attachment_link( $link, $attachment_id ){
$attachment = get_post( $attachment_id );
// Only for attachments actually attached to a parent post
if( ! empty( $attachment->post_parent ) ) {
$parent_link = get_permalink( $attachment->post_parent );
// make the link compatible with permalink settings with or without "/" at the end
$parent_link = rtrim( $parent_link, "/" );
$link = $parent_link . '/gallerie/' . $attachment_id;
}
echo $link;
}
add_action( 'init', function() {
// Tell WordPress how to handle the new structure
add_rewrite_rule( '(.+)/gallerie/([0-9]{1,})/?$', 'index.php?attachment_id=$matches[2]', 'top' );
} );
The problem I encounter is that the displayed content is an array, not the image. Since the permalink is working, I wonder why wordpress is unable to display the image.
Any idea?
Regards.