How to test if there are no more previous or next image on attachment page?

You need to use the adjacent image link filters, defined in the source of adjacent_image_link() function. Example: add_filter( “next_image_link”, “cyb_next_image_link”, 10, 4 ); function cyb_next_image_link( $output, $attachment_id, $size, $text ) { if( $output == ” ) { return ‘<div class=”next-image”><span>NEXT</span> <i class=”fa fa-angle-right”></i></div>’; } return $output; } add_filter( “previous_image_link”, “cyb_previous_image_link”, 10, 4 ); function cyb_previous_image_link( … Read more

Delete post image attachments with jQuery from the front end

Now you need to handle the AJAX call in PHP. add_action( ‘wp_ajax_delete_attachment’, ‘delete_attachment’ ); function delete_attachment( $post ) { //echo $_POST[‘att_ID’]; $msg = ‘Attachment ID [‘ . $_POST[‘att_ID’] . ‘] has been deleted!’; if( wp_delete_attachment( $_POST[‘att_ID’], true )) { echo $msg; } die(); } As for your event, just add it to the click function … Read more

How to get image URL from media_sideload_image?

Try the fourth input parameter (available in 4.2+): @param string $return Optional. Accepts ‘html’ (image tag html) or “https://wordpress.stackexchange.com/questions/212512/src” (URL). Default ‘html’. So change your code snippet to: $new_image_url = media_sideload_image($new_url, $post_ID, $title, $src=”https://wordpress.stackexchange.com/questions/212512/src” ); to get the src instead of the default html. Note that the output might also be an WP_Error object for … Read more

Looking to limit file attachment downloads

If your attachment is handled via the WP media library, each one has unique ID, just like Posts. When your users download the attachment by clicking the button, store a reference to that attachment ID in a user_meta setting and then update the button accordingly. Another option: https://easydigitaldownloads.com/

Search by Attachment ID

The WP_Query class can match IDs as well as search terms. An idea would be to use the pre_get_posts action to detect if the search term is numeric and, if it is, set the query to work with attachments while passing the search as the ID. function wpse223307_allow_search_by_attachment_id( $query ) { //Only alter the query … Read more

Get Attachment Category Name

The answer was found here: http://www.wprecipes.com/how-to-display-category-name-without-link For my purposes, I needed to define the category function and then call it by name-only inside the php echo: <?php $category = get_the_category($attachment->ID); echo ‘html goes here’; echo ”.$category[0]->cat_name.’; ?> Additionally, to help eliminate space or punctuation in the category name, it can display the slug instead: <?php … Read more

How to add a caption to an image attachment in a file list?

You simply need to pass $attachment_id instead of get_post_thumbnail_id() in echo get_post(get_post_thumbnail_id())->post_excerpt; with wptexturize to prevent your markup from breaking other things. Update: As @birgire suggested I think it is better to use get_post_field() instead of directly accessing post property. Updated code:- function soth_output_gallery_file_list( $file_list_meta_key, $img_size ) { // Get the list of files $files … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)