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 create custom URL routes?
- How do you create a “virtual” page in WordPress
- How To Retrieve An Image Attachment’s Alt Text?
- How to get image title/alt attribute?
- How to create a front end user profile with a friendly permalink
- Programmatically adding images to media library
- Use a template file for a specific url without creating a page
- Using the Rewrite API to Construct a RESTful URL
- Does WordPress keep track of a post’s URL history and provide automatic redirects?
- Creating an Image-Centric Custom Post Type?
- How does WP media uploader create the 3 different sized images, and how can I duplicate it
- Change the “page” slug in pagination
- Programmatically get images by URL and save in uploads folder
- Understanding add_rewrite_rule
- how to get original image using wp_get_attachment_image_src
- Override default url for author pages?
- Can I attach image to post without adding it to post?
- Get the first image from post content (eg.: hotlinked images)
- web.config conflict on IIS
- Rewrite Slug for CPT Archive Pages to Plural Name of Slug
- Change author base slug for different roles
- Remove Dimension from wp_get_attachment_image
- Two (or more) parallel (sub-)TLDs that are retained when surfing the site / dynamically set the site address?
- Using custom/dynamic “slug” for a page
- How to make pages slug have priority over any other taxonomies like custom-post, post or category
- getting attachement images src and add classes
- Rewrite rules not working in WordPress
- How to retrieve $_GET variables from rewritten URLs?
- Dynamic Endpoints
- remove links from images using functions.php
- Passing parameters to a custom page template using clean urls
- Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
- rewrite rules and querystring
- Adding rewrite endpoint breaks static front page
- How to add custom rewrite rule to .htaccess?
- How do I remove a rewrite rule?
- How do I add a server-independent external rewrite rule?
- Multiple endpoints to same page
- Problem with add_rewrite_rule and pagination (paged and page query_vars)
- Use subdomain for certain urls
- Disable image attachment links
- wp_get_attachment_image_src and server path
- Custom Permalinks for Blog Posts Only
- Unique URL Every Time
- Check if post has attachments (not image)
- How to add a class to the attachment images
- generate_rewrite_rules (action) vs add_rewrite_rule (function): which one is preferred?
- Detect page type by url (Archive, single, page, author,…)
- Rewrite URL – how to do a SEO-friendly Unicode custom URL?
- How to find attachment by it’s name?
- I want to create a custom slug in WordPress and output JSON. How do I do this?
- How to make a category page the blog home page?
- add_rewrite_rule: $matches var not replaced by captured value
- Find the post an attachment is attached to
- Can I call a custom plugin with a direct URL
- How to show the same content on multiple URLs?
- Custom slug in front of search URL
- Display posts with author in the url with custom post types
- Custom rewrite rules for pages
- Rewrite default post type
- Custom permalinks with NextGEN Gallery
- Validate alt text for attachments?
- Clash of the rewrites
- Using a page template without a page
- External/non-WP rewrite rules
- How-to add rewrite rules to point the uploads folder to a subdomain
- List most recent image uploads, but only for specific custom post type
- Applying automatic link class to images embedded to posts
- How do I detach images from posts?
- Count the number of images uploded on the website
- Rewrite Rules for Multiple (more than 2) Taxonomies
- How do I delete all generated images from my server except those currently used in posts
- How to paginate attachments in a secondary query as gallery?
- Create built-in pages without creating actual pages
- Insert an image into a post by API
- How to seamlessly redirect between different archive and singular slugs?
- Function to call the attachment image from post
- Is the SEO plugin necessary?
- Can ‘numberposts’ be passed in the URL query string?
- How to add dot(“.”) in post slug
- How to prevent redirection to max 2147483647 for larger values of the page query variable?
- How to add classes to images based on their categories?
- add_rewrite_rule not loading correct page nor getting variables
- Overwrite rewrite-slug of built in post-type ‘post’
- Preserving $_GET parameter while using custom Rewrite Rule
- How to change default page slug?
- Query Vars for the Homepage?
- Disable wordpress pagination URL rewrite for specific page
- How to use Post Custom Metadata in Post Titles and Post Permalinks
- Using WordPress with Apache behind an nginx reverse proxy
- Handle category name URL rewrite before different post type slugs