Make pretty permalinks work for attachments
-
Hey all,
I have for the first time needed to create an attachment template, but permalinks for this template are not working as I would expect.
I have my permalinks set to the ‘Post name’ structure
(/%postname%/)
, and while that works fine for things like the author template, it doesn’t work for attachments.For example, this is what I get for a author permalink –
–https://www.mysite.com/author/aname/
This is what I expect to get for the attachment permalink –
–https://www.mysite.com/attachment/media-slug/
What I actually get for an attachment permalink –
–https://www.mysite.com/?attachment_id=111
I have tried to manually add some rules (followed by re-saving the permalink structure to unsure the
generate_rewrite_rules
action was called) –add_action('generate_rewrite_rules', 'djg_attachment_rewrite_rule'); function djg_attachment_rewrite_rule($wp_rewrite){ $new_rules = array(); $new_rules['attachment/(\d*)$'] = 'index.php?attachment_id=$matches[1]'; $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; }
However, I can’t get attachment permalinks. Does anybody know how to do this, and why WP doesn’t do it out of the box?
Thanks
- The topic ‘Make pretty permalinks work for attachments’ is closed to new replies.