How can I prevent uploading bmp image?

The magic is in get_allowed_mime_types() which calls the upload_mimes filter. That is filtering a default array consisting of keys as a non-terminated regular expression of file-extensions and the mapped mime-type as values: array( ‘jpg|jpeg|jpe’ => ‘image/jpeg’, ‘gif’ => ‘image/gif’, ‘png’ => ‘image/png’, ‘bmp’ => ‘image/bmp’, ‘tif|tiff’ => ‘image/tiff’, ‘ico’ => ‘image/x-icon’, …. } so hooking … Read more

How to prevent upload of a multiple sizes of images

I believe those are probably generated by the default WordPress sizes – thumbnail, medium and large. (See Appearance > Media for where those sizes are set). If you want to eliminate the extra image sizes the simplest way might be to eliminate some of your theme’s custom image sizes and use the defaults instead. OR, … Read more

Change the output for [gallery] shortcode

The source for the gallery shortcode is in wp-includes/media.php. There are a couple of hooks in there that might work for you. Without knowing exactly what you want to do, it is impossible to be more specific. If that doesn’t work then you can remove the shortcode: remove_shortcode(‘gallery’); And add another gallery shortcode with the … Read more

Using file_exists to check file in Uploads

You can’t use a file url in file_exists() like this: file_exists( “http://example.com/wp-content/uploads/Example_Name_2_SM.jpg” ); You should rather use an absolute file path, for example: file_exists( “/absolute/path/to/wp-content/uploads/Example_Name_2_SM.jpg” ); Then you should try $meta = get_post_meta( $post->ID, ‘_meta_example_name’, true ); $file = $upload_basedir . “https://wordpress.stackexchange.com/” . $meta . ‘_7_SM.jpg’; if ( file_exists( $file ) ) { //… } … Read more

Create Image Uploader for Widget

Let’s face it in detail: The registered sidebar (with the ID left-sidebar) has two arguments to wrap the whole widget (before_widget and after_widget) which you can output via echo $before_widget and echo $after_widget in your widget (see my version below): <?php // Register sidebar if (function_exists(‘register_sidebar’)) { register_sidebar( array( ‘name’ => ‘Left Sidebar’, ‘id’ => … Read more

Automating a Daily Picture Blog?

There are lots of ways to accomplish a daily picture blog so I’ll just give you how I’d approach it. If I wanted to set up a photoblog on WordPress I’d start with a Flickr account and leverage it (or if you don’t like Flickr for some reason you can also look at PhotoBucket, SmugMug, … Read more

How do I exclude all images from a wp_query?

Pretty much the solution is to include all mimes except images. WordPress has a nifty little function where it keeps all it’s accepted mime-types called get_allowed_mime_types() ( cleverly named ) which returns an Array() of mimes. All we need to do is get the difference between the returned array and the array of mime-types we … Read more

How to make WordPress use protocol indepentent upload files?

You can define a function to remove the protocol and hook it to the attachment URL: function wpse_79958_remove_protocol_from_attachment($url) { $url = str_replace(array(‘http:’, ‘https:’), ”, $url); return $url; } add_filter( ‘attachment_link’, ‘wpse_79958_remove_protocol_from_attachment’ ); Also consider to use relative URLs for attachments by using WordPress builtin function wp_make_link_relative: add_filter( ‘attachment_link’, ‘wp_make_link_relative’ ); Place this code to your … Read more