Get the attachment URL on single.php

The the_attachment_link returns an HTML link, so use this code: if ( $attachments = get_children( array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘numberposts’ => 1, ‘post_status’ => null, ‘post_parent’ => $post->ID ) ) ); foreach ( $attachments as $attachment ) { echo wp_get_attachment_link( $attachment->ID, ” , true, false, ‘Link to image attachment’ ); } Here … Read more

ID of images from gallery

You can find out the IDs of which images are included in a gallery by switching to the Text editor tab and look for a piece of code like this: The comma-separated list of image IDs are enclosed in the ids attribute If you’re looking to find out IDs of existing images in order to … Read more

copy attachment title to description and alt text

You can make a query to loop through all the attachments, and then update the attachment info for each attachment in the while loop. Something like $args = array( ‘post_type’ => ‘attachments’, ‘post_status’ => ‘any’, ‘posts_per_page’ => -1, ) $query = new WP_Query($args) if($query->have_posts()): while($query->have_posts()): $query->the_post(); // 1. Get the attachment filename here and store … Read more

How to upload image from front end and save in media library?

Now I have an answer for my own question.I solved this issue by using this code.I add this code just for sharing and helping other as it works for me. <input type=”file” name=”my_file_upload” id=”my_file_upload_id” class=”bg_checkbox” > function register_team_show_case_setting() { //register our settings register_setting(‘my_team_show_case_setting’, ‘my_file_upload’); } add_action(‘admin_init’, ‘register_team_show_case_setting’); Code to upload and save image: require_once( ABSPATH … Read more

Change the Permalink for wordpress attachment

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 … Read more

Delivering a file instead of wordpress page

You’re on the right path with a rewrite rule. If you’re just delivering a file, you can hook an early action, check if a download was requested, then output the file and exit before WordPress ever gets to the stage of querying the database and deciding the request is a 404. // add the download … Read more