Hook wp_get_attachment_link for this purpose. Here is an example of how to do it –
function attachment_link_filter( $content, $post_id, $size, $permalink ) {
// Only do this if we're getting the file URL
if (! $permalink) {
// This returns an array of (url, width, height)
$image = wp_get_attachment_image_src( $post_id, 'large' );
$new_content = preg_replace('/href=\'(.*?)\"https://wordpress.stackexchange.com/", 'href=\'' . $image[0] . '\'', $content );
return $new_content;
} else {
return $content;
}
}
add_filter('wp_get_attachment_link', 'attachment_link_filter', 10, 4);
Related Posts:
- How can I add an image upload field directly to a custom write panel?
- Checking if a file is already in the Media Library
- Standard location for plugin to save/cache files?
- Saving data-URI to media library
- Can I use the wp media uploader for my own plugin?
- Change Media Uploader default directory
- Changing upload directory for plugin uploads only
- Upload file to remote storage
- Why are two functions over-riding each other?
- WordPress Media mime type filter problem 4.0
- Using the component outside the editor. select(‘core’) is null
- Getting Details Of Uploaded Image
- Sharing a common set of image files for media library, across all sites within multisite
- Uploading images from a custom page using blueimp uploader?
- Hook to get image filename when it is uploaded
- How to send email in wordpress with more than one attachments
- Using the default wordpress uploader inside plugin
- Files automatically added
- What filter should I use to insert a button inside on Media>Add New
- Changing upload dir in a plugin regardless of post type
- How to replicate Media Library “Add New” on Plugin Settings Page
- Plugin writing: access file that was just uploaded
- Custom delete option button in plugin settings
- How to enable sorting in custom media uploader in plugin
- Create a new post using rest api and save featured image using an external image url
- Why is the temporary upload always 4.1K
- Upload multiple images and insert them into custom html code
- wp_editor add media button not working
- WordPress Specified file failed upload test
- How to create a digital product download link that can’t be used twice?
- How to submit/upload data to database and in specific folder?
- Cleaning a filename after image sideloading a url that contains `%20`
- Get audio metadata on file upload
- How to move an image in a plugin to the upload directory and make it as a media of wordpress?
- Why doesn’t update_post_meta work for certain strings?
- wp.media Uncaught TypeError: Cannot read properties of undefined (reading ‘state’)
- Insert and read media from the WordPress library and call in the plugin
- Trying to rename a file upload as the hash of file content on wordpress
- Home page is not loading, where in other pages are displaying on the site
- WordPress5.2.3: Better File Download Plugin validation issue
- WordPress discards PNG file when uploading plugin file
- Hook for validating and rejecting frontend image upload
- Changed media upload path for plugin, but generates error & shows wrong url
- How to destroy or dispose wordpress uploder/manager?
- Displaying $_FILES data (simlar to $_POST)
- Changing upload directory for plugin uploads only
- How do you filter get_media_items by mime type in a custom media upload tab?
- Is it possible to convert various image types from remote URLs to WebP and then serve them immediately?
- upload script in plugin development [duplicate]
- Leveraging Core Functionality in Icon Upload Plugin [closed]
- Upload to a specific media folder created by FileBird Lite
- Load images from CDN and custom features to “Add Media” dialogue
- upload image to wordpress media library failed for custom post type
- What’s the best method for emptying an option created with the Settings API?
- template_include (overriding default plugin templates via current theme)
- Using composer for dependency management in plugindevelopment
- What is nonce and how to use it with Ajax in WordPress? [duplicate]
- Update exisiting site to 3.5 release candidate
- Why does do_action pass a blank string as the first parameter if no $arg is set?
- add_filter and remove_filter added before and after wp_query
- What is the difference between strip_tags and wp_filter_nohtml_kses?
- How can I hook into existing WordPress Bulk actions?
- How to bundle a plugin with a theme, or vice versa
- creating elements/innerblocks via rangecontrol
- How to check if current static page is frontpage from admin plugin
- Woocommerce add custom button to backend order table
- Earliest WP Hook to Safely and Reliably Redirect
- How can I display an error message after post has been saved?
- What method to use to call a REST API?
- How to add a secondary button to a settings page with a custom action?
- Some strings from a .mo file do not load
- Add a row on clicking each post featured image
- How can I gracefully escape an error condition?
- Plugin development: can’t update settings with multiple settings sections
- How can I add a custom “Text” widget to Appearance manager from functions.php?
- How to do POST request with WP REST API v2 to custom table?
- Filter Categories widget to allow custom sorting?
- How to allow only two (or more) users access to a plugin
- Special Formatting for WordPress Plugin Description?
- Plugin Development – Get Admin Url (Including cases where wp-admin is not used)
- Add code to template dynamically
- How Can I Add Code To A Preexisting Function Without Editing it
- Creating posts with links from a txt file
- Change the behaviour of a button
- escape html in jQuery for WordPress
- Progress bar in plugin within admin
- WordPress admin panel not working
- Redirection from a specific page for users logged in but not with membership
- Load script on frontend from widget plugin
- Can’t get wpColorPicker to work in a widget
- WordPress Plugin Update Process
- Ajax functionality not being called under wordpress plugin
- Registration form Plugin… Email confirmation
- Can’t add images in wordpress to my page – button isn’t clickable
- Gutenberg and custom blocks messed up pagespeed score. What did I wrong?
- Gutenberg text field validation
- I don’t understand how symlinks in plugin work
- Need someone to help you want to manage points for members to code interface functions? thank you
- Call API on post save/update and show the result in admin area
- Is there any other ways to replicating changes on live from staging without pushing from git