Get image path : image is upload but not attached

This is not very reliable in general (especially not in multisite environment), but for specific case it can be good enough: $url=”http://localhost/wp-content/uploads/2011/06/sample.jpg”; $uploads = wp_upload_dir(); $path = str_replace( $uploads[‘baseurl’], $uploads[‘basedir’], $url);

Best way to receive special images in posts

WordPress already does the heavy lifting for you on this. All you need to do is use post thumbnails. If you don’t see the featured image meta box on your pages/posts, place the following in your functions.php file. add_theme_support(‘post-thumbnails’); From there you will need to define a new image size in your functions.php file. add_image_size(‘special-image’, … Read more

Right click&copy images: protection

This functionality is Plugin territory. I strongly believe that the WordPress core team will never consider such functionality for WordPress core. Besides: such functionality is also pointless. Anyone who wants an image badly enough is going to be able to get them. (They can disable javascript thereby defeating the Plugin entirely; they can view source … Read more

Images don’t update after being edited

When you upload an image via the media library, additional sizes are created: large, medium, thumbnail, plus any additional sizes defined by plugins or your theme. If your theme displays any sizes other than the original, un-resized image, you’ll have to regenerate those additional sizes to see any changes take effect. If this is the … Read more

How to resize attachement

If you are trying to retroactively resize images, use the code you’ve supplied in your functions.php, then run the Regenerate Thumbnails plugin http://wordpress.org/extend/plugins/regenerate-thumbnails/ Once you’ve done that you should be able to display the image using the following: the_post_thumbnail(‘my_thumb’);

Uploading images in custom post form

Let’s presume your FILE variable is called ‘files’ and can contain multiple inputs (i.e. name=”files[]”) 1) First upload the files $uploads = wp_upload_dir(); $upload_file_url = array(); foreach ($_FILES[‘files’][‘name’] as $key => $value_data) { $errors_founds=””; if ($_FILES[‘files’][‘error’][$key] != UPLOAD_ERR_OK) $errors_founds .= ‘Error uploading the file!<br />’; if (!array_key_exists($_FILES[‘files’][‘type’][$key], $mime)) $errors_founds .= ‘Invalid file type!<br />’; if … Read more

How to change background image from WordPress Gallery

The background image is applied to the <body> element, so using jQuery, all you really need to do is add a .click() handler to the $(‘dt.gallery-icon img’) element, grabbing its src attribute and applying it to the body’s background-image. EDIT: I thought this would be an interesting exercise, so here is a plugin that does … Read more