the_content() behavior on attachment.php versus single.php

This is correct behavior, if your attachment doesn’t actually have anything in post_content field (which is quite common). When post–centric templates run, prepend_attachment() is used as filter to “emulate” post content. This is not the case with template “intended” for attachments. If you look at template-loader.php: elseif ( is_attachment() && $template = get_attachment_template() ) : …

Read more

Is it possible to modify the media library admin screen?

That area of all admin screens is where admin notices are displayed, so you could generate an admin notice. Here’s a suitable function and hook: function wpse_233031_admin_notice() { ?> <div class=”notice notice-info”> <p>Your message here!</p> </div> <?php } function wpse_233031_hook_admin_notice() { add_action( ‘admin_notices’, ‘wpse_233031_admin_notice’ ); } add_action( ‘load-upload.php’, ‘wpse_233031_hook_admin_notice’ ); /* Edited out anonymous function …

Read more

How can i change an image’s author?

You can use wp_update_post() $my_post = array( ‘ID’ => $post_id, ‘post_author’ => $user_id, ); wp_update_post( $my_post ); Or change image’s author via a function using GravityForms uploader add_action(“gform_user_registered”, “image_author”, 10, 4); function image_author($user_id, $config, $entry, $user_pass) { $post_id = $entry[“post_id”]; $args = array( ‘post_parent’ => $post_id, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’ ); $attachments = …

Read more

sanitize attachment filename

Following on from question comments. You can run a filter on sanitize_file_name_chars and add the degree symbol to the array of invalid chars, but it won’t halt the upload it will simply strip the file extension. However you can add another filter stop the upload, in a hacky kind of way by additionally hooking on …

Read more

Limit amount of results returned

$images = $wpdb->get_col(” SELECT ID FROM $wpdb->posts WHERE post_type=”attachment” AND ID in ($meta) ORDER BY menu_order ASC LIMIT 5 “); Like @Kaiser suggested you can specify a range (5th to 20th results, a total of 15 results are returned at max) like this: $images = $wpdb->get_col(” SELECT ID FROM $wpdb->posts WHERE post_type=”attachment” AND ID in …

Read more

Link Featured Thumb to Attachment Page, If Possible

Question 1: How do you link Featured Image to its Attachment Page In the loop: <?php if( has_post_thumbnail() ) : ?> <a href=”<?php echo get_attachment_link( get_post_thumbnail_id() ); ?>”> <?php the_post_thumbnail(); ?> </a> <?php endif; ?> Question 2: Post Format Templating Post formats are actually just a custom taxonomy with a fancy UI. Hence, you should …

Read more

wp_insert_post featured image from library

You can use the function set_post_thubmnail(). After you inserted your post, just call this one, and you are ready to go. $yourpostid = wp_insert_post( $args ); // Define the post in the args first set_post_thumbnail( $yourpostid, $thumbnail_id ); // set the ID of your thumbnail to be the featured image of your newly created post.