How does wordpress add an a tag to the uploaded image to link it to the image url? Most online methods are added through js, but they are not. Wordpress itself provides this function.
When uploading the media library, select Attachment Display Settings ->Link to Media Files.
It is troublesome to set each time. If you encounter batch or collected pictures, you can use the following code to fix the default options.
/** *Set as default link to media files */ update_option('image_default_link_type', 'file');
Add code to functions.php
Save anywhere