How to remove the whitespace in image name and save the new file

Use sanitize_file_name( $filename ). This function doesn’t just catch white space, it removes other special characters too: $special_chars = array( “?”, “[“, “]”, “https://wordpress.stackexchange.com/”, “\\”, “=”, “<“, “>”, “:”, “;”, “,”, “‘”, “\””, “&”, “$”, “#”, “*”, “(“, “)”, “|”, “~”, “`”, “!”, “{“, “}”, chr(0) ); Find the following line in the plugin’s code: … Read more

Check if page/post has any anchors that link to an image jpg/gif/png

This method has worked in the past for checking if a shortcode exists on a page. You will have to test it and see if it fires in time to enqueue the javascript> add_filter(‘the_posts’, ‘c3_image_check’); function c3_image_check($posts){ if (empty($posts)) return $posts; $img_found = false; foreach ($posts as $post) { if (stripos($post->post_content, ‘<img src=”https://wordpress.stackexchange.com/questions/53585/)) { $img_found … Read more

WP 3.4 has missing photo data

Having figured out the issue, I’d like to update this question. The issue stems from previous versions of WP not including the _wp_attached_file meta key when uploading media, which 3.4 now seems to require. Below is PHP code for looping through the database, verifying the presence of both the key and image file, then updating … Read more

Adding a querystring to an image URL when clicking ‘insert into post’?

You need to use the filter image_send_to_editor. add_filter(‘image_send_to_editor’, ‘wpse_62869_img_wrapper’, 20, 8); function wpse_62869_img_wrapper( $html, $id, $caption, $title, $align, $url, $size, $alt ) { return $html; } These are the values of a test insert and you can use them to build your own $html response. html | <a href=”http://wp34.dev/wp-content/uploads/2012/11/escritorio.jpg”><img src=”http://wp34.dev/wp-content/uploads/2012/11/escritorio-224×300.jpg” alt=”Alt text for the image” … Read more

Show Post Excerpt in Image Attachement

First refer to this answer by @MikeSchinkel. You can put the function in functions.php Next, just add echo robins_get_the_excerpt($post->post_parent); below the image attachment. Like this : <div class=”caption”> <?php echo robins_get_the_excerpt($post->post_parent) ?> </div> Please note that this code is untested.

Actions according to image type and size

That function looks like the kind of thing that would slow down a site. 🙂 The first thing I’d recommend is that you not run that function on the front end. Run it when the image is uploaded and store the result in the database using wp_update_attachment_metadata. You can then retrieve the data with wp_get_attachment_metadata. … Read more