Create an attachment template file within the theme. Since we are only interested in images, the file should be image.php
<?php
if ( have_posts() ) {
the_post();
$image_url = wp_get_attachment_url();
}
header('Location: '.$image_url);
?>
Related Posts:
- Change default URL of image attachment
- Masking wp-content/themes/name/images to just images directory using htaccess
- copy attachments to another post type and change attachment url
- Attachment Page Permalink/URL Rewrite Issue. How to change the actual rewriting?
- How do I change attachment slug from name to id
- How to remove parent section from attachment URL?
- Attachment page gives 404 if user not logged
- custom url – add attachment’s id or name after post
- Import images from self-hosted to WordPress.com
- How To Retrieve An Image Attachment’s Alt Text?
- Rewrite Slug for CPT Archive Pages to Plural Name of Slug
- Change author base slug for different roles
- Problem with add_rewrite_rule and pagination (paged and page query_vars)
- Custom Permalinks for Blog Posts Only
- Detect page type by url (Archive, single, page, author,…)
- Using a page template without a page
- Overwrite rewrite-slug of built in post-type ‘post’
- Why does wordpress still strip my query var?
- URL rewrites and pagination
- Separate attachment images from post loop
- Rewrite rules goes away
- How to get meta value in wp_attachment_metadata
- How to change page URLs to “www.site.com/page” instead of “example.com/blog/page” but keep post URLs as “example.com/blog/post”?
- Conditional Statement – check if post has an attachment image
- Allowing post attachments without allowing to insert in text
- Add_query_arg + two times the same argument?
- How do I create Comma Separated list of attached image ids?
- Redirecting all old links from previous EE site to new WP site in one go?
- attachment url rewrite
- Two “.htaccess” Files Located in Different Directories?
- Removing the post format (type) slug
- Redirect all posts urls from without .html to .html
- Converting a simple plugin to be placed inside of functions.php
- Single Redirection Rule for Pages and Archive links
- Home page with Polylang redirects to other page [closed]
- Image Attachment Url Rewrite
- expecting 404 but redirecting to post with url subdirectory in post title
- Custom user profile URLs
- query attachment images … if no attachments -> get attachments of parent page?
- Rewrite of URL with ‘[‘ ‘]’ or ‘(‘ ‘)’ as literals
- Define orderby in url
- get_attachment_id() only get id of first attached image after post update
- Get the url of the full sized attachment image using post ID?
- Custom page template to display all image attachments
- Changing RSS feed URL structure
- Preserve Domain Alias
- Mobile version issue when domain forwarding with masking
- WordPress Rewrites – How can I pass a variable to Custom Post Type?
- How can I attach hotlinked images in posts/pages within the same server?
- WordPress Image Attachment using remote image
- Need to add rewrite rule that adds in additional information about the post to url
- add_rewrite_rule is redirecting instead of rewriting url
- Rewrite rules automatically for pages using specific template
- Add language prefix to permalinks
- Custom Rewrite rule to captured post (rewrite rule to rewrite rule)
- Replacing the content of an image attachment using API
- How to change the Author Slug from Username to Nickname and deal with Special Characters
- Clean up images, delete unused image sizes attached to a post type
- How to pass url as a parameter in a add_rewrite_rule
- Per Page Permalink Structure for Page Post Type
- get_post_meta not working on category.php
- RSS feed rewrite matching wrong rule
- How do you get the full size url of an attachment image
- WordPress Creates Unused (Unregistered) Image Sizes
- Replace “http://localhost:8888/” by website URL in WordPress
- Thousands of 404 errors on old posts due to embedded links
- WP Rewrite for a custom variable
- Possible to add “Even/Odd Classes” to image attachments via wp_get_attachment_image?
- How to get post id of first child of the same post type?
- How do I get posts to appear at mydomain.com/blog?
- rewrite rules and capturing
- How to change search page url so that it still returns a page when there’s no search query specified?
- How to echo images Urls from a wordpress post, that are relally in the post
- Custom taxonomy named ‘tag’ return 404 page
- Multiple permalink with and without category for same post
- Help adding custom url, rewrite_rules_array
- Implementing geotargeting while using a single database
- Url rewrite, add rule, redirect as POST request?
- Broken page redirect
- Homepage cannot be found
- Remove trailing slash
- Rewrite Url to a SEO-friendly format
- Use Parent Pages for URL Structure without Landing Page
- add_rewrite Rule
- How to show my application as referral in WordPress Stats
- Open image size links in a page instead of direct image link
- Create a custom attachment thumbnail for quick page load
- Redirect A URL Pattern In WordPress Using .htaccess
- Help to cleanup this code
- Rewrite Question
- Change the search URL
- How to make a custom route with any-string-part/number-part pointing to an existing page?
- username in rewritten URL, howto use it in a template
- Rewwrite rule for mapping plugin static file
- Listing Authors – URL Formats [duplicate]
- wordpress url rewrite Query Var to Static url
- Add rewrite endpoint and .htaccess
- Remove url parameter using wordpress
- Change the slug ( url ) to a sequence number starting from 0 in the custom record type?
- Change url site.it/wordpress