Your rule works with the attachment ID, so I’m not sure how you’re using the title, but the answer is almost identical in either case. The filter you want is attachment_link
:
function wpd_attachment_link( $link, $post_id ){
$post = get_post( $post_id );
return home_url( '/images/' . $post->post_title );
}
add_filter( 'attachment_link', 'wpd_attachment_link', 20, 2 );
Change $post->post_title
to $post->ID
to put the ID in the URL instead of title.
Related Posts:
- URL rewrite with add_rewrite_rule and attachment_id
- How To Retrieve An Image Attachment’s Alt Text?
- How to manage attachment relationships for specific posts in WP 3.5+
- Can I add a Category Metabox to attachment?
- Change attachment filename
- How to get attachment file name not attachment URL
- How to trigger a refresh in the media modal
- Get all post attachments except featured image
- Programmatically adding images to the media library with wp_generate_attachment_metadata randomly fails
- getting attachement images src and add classes
- How can I bulk delete media and attachments using WP-CLI?
- Getting a taxonomy’s thumbnail url
- Check if post has attachments (not image)
- How to cleanly delete attachment but retain original file?
- Changing attachment urls?
- Add custom class to attachment in media library grid mode
- Are captions stored anywhere?
- Trying to hide buttons from Attachment window
- get_the_post_thumbnail() doesn’t taking style attribute
- Expanding new Media Uploader in WordPress 3.5
- How can I UN-attach media from a post?
- Uploading Multiple Attachments From Front-End With A Description
- Validate alt text for attachments?
- complex restriction of items in media library
- Remove duplicate attachments
- Edit image / Delete image link
- How could I add button next to “edit image” button in “Attachment Details”
- Applying automatic link class to images embedded to posts
- How to get attachment caption (get_the_excerpt gives parent post excerpt) ?
- Is it possible to query specific WordPress Attachment files (.ppt & .pdf) and output them in a list?
- media_sideload_image file name?
- Get all posts (of any post type) an attachment is used in
- Detect if is image unattached
- How to single click to download image in single post
- delete attachment from front end
- Unattaching unlinked images
- How to get attachments for a specific post type?
- Give attachments an archive page
- custom fields for attachments?
- Insert Media – Attachment – Link to : Remove the “attachment page” option
- Show Post ID in “Find Posts or Pages” box in Media Library?
- How to add media from front-end to an existing post?
- How to set author for post AND post attachments
- Can I attach a document (eg: PDF) but have a JPEG as a thumbnail?
- Retrieving a custom link on an attachment
- Get attachment from post
- How can I display custom fields value from attachment media?
- Delete attachments from Front end
- Add column for attachment file size
- Creating a multi-file upload form on the front end for attachments
- how to test for attached image
- Unable to upload specific .zip file type via frontend in WordPress 4.0
- Get attachments (get_posts) and WP 3.5 new uploader
- get post attachments of a particular size
- Change image link: wp_get_attachment_link
- Multi-line captions on attachments
- Make individual attachments private?
- exposing attachment uploading to the front end — delicate
- Gel all image from certain post type
- Making images from single.php pointing to an attachment .php template
- Add_Filter example for wp_get_attachment_link
- How to upload image from front end and save in media library?
- Can i hide the attachments from media which I uploaded from front end?
- ID of images from gallery
- Get the attachment URL on single.php
- How to get list of paths (not urls) for an image
- wp_get_attachment_image_src always returns false
- Exact image sizes
- attachment url rewrite
- Get the size (size in Kb or MB) of an featured image?
- Adding attachment file name to email link
- Automatically delete attachments and posts [closed]
- How to allow specific extensions and file size to wp_mail attachment?
- Get attachment file link
- How to grab the first two image attachments from a post?
- wp_insert_post featured image from library
- How to delete orphan attachments?
- the_content() behavior on attachment.php versus single.php
- How to count media attachments?
- How to create a CSV on the fly and send as an attachment using wp_mail?
- attachments with tags and get_posts
- Hide “Gallery Settings” and “Insert into Post” button from Attachment window
- Get the title and URL of the attachment parent post
- How can I change wordpress attachment url and protect it?
- Confused with attachment mimetype order
- Insert custom ID into wp_get_attachment_link
- Adding class to next/prev image link in attachment.php
- Disable edit media attachments?
- query attachment images … if no attachments -> get attachments of parent page?
- Replacing with(out) regex link to attachment by links to files
- Getting ID from ajax response of async-upload.php
- How to add attachment without uploading?
- Post Auto Draft Issue
- Getting attachment images is cloning some of them
- How to add multiple checkbox elements to media attachments?
- Get attachment next and previous by author only
- Edit default image attachment size
- Perform a custom (bulk) action in media view
- How to make a customized “Create Gallery” tab in the ‘Add Media’ window?
- Reorder “menu order” of attachments to another predefined order