Attachment posts showing an array (issue | url rewriting)
-
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.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Attachment posts showing an array (issue | url rewriting)’ is closed to new replies.