media_sideload_image file name?

When I started using media_sideload_image(), I found it pretty useless as it returned a full html tag, instead of the attachment ID, so I created my own version of it which replicates all the functionality of media_sideload_image() and adds some very useful stuff, like: saving the sideloaded file under a completely new filename making the … Read more

How to paginate attachments in a secondary query as gallery?

I’m assuming you want something like this: |———————| | content | | (static) | |———————| | gallery | | (paged) | |———————| | << pagelinks >> | |———————| In this setup your the post content stays the same, appears to be static, while the gallery is paged. This means you have the main query, showing … Read more

Is it possible to query specific WordPress Attachment files (.ppt & .pdf) and output them in a list?

I don’t think it’s documented in Codex but quick search in code shows that you can query by mime type. For jpeg images that would be something like: $posts = get_posts( array( ‘post_type’ => ‘attachment’, ‘post_status’ => ‘any’, ‘post_mime_type’ => ‘image/jpeg’, ) ); Not sure what types WP uses for files you need, don’t have … Read more

Count the number of images uploded on the website

There’s a handy built-in function, namely wp_count_attachments(). We can filter out images with wp_count_attachments( $mime_type=”image” ) that returns an object like: stdClass Object ( [image/gif] => 9 [image/jpeg] => 121 [image/png] => 20 [image/x-icon] => 6 [trash] => 0 ) So we can use the one-liner: $count = array_sum( (array) wp_count_attachments( $mime_type=”image” ) ); for … Read more

How do I detach images from posts?

If you view the Media Library in the list mode: /wp-admin/upload.php?mode=list then you will see the Attach/Detach links for each attachment. Each attachment can only be attached to a single parent through the post_parent field in the wp_posst table. Deleting an image from the post editor will not change the post_parent field to 0. Making … Read more

Applying automatic link class to images embedded to posts

You can run a filter on image_send_to_editor, the filter runs inside the get_image_send_to_editor function which is resposible for sending the link HTML that surrounds images sent to the editor. The filter can be found in core, in wp-admin/includes/media and is linked below for quick reference. core.trac.wordpress.org/browser/tags/3.1/wp-admin/includes/media.php