Automatically wrap post image in div

It’s the image_send_to_editor filter: if(is_admin()){ add_filter(‘image_send_to_editor’, ‘wrap_my_div’, 10, 8); function wrap_my_div($html, $id, $caption, $title, $align, $url, $size, $alt){ return ‘<div class=”mydiv” id=”mydiv-‘.$id.'”>’.$html.'</div>’; } } For existing images/posts you can try the regex in the function below

Issues renaming images during upload

Sent Header The following error simply states that the error message was output directly (sent header) Warning: Cannot modify header information – headers already sent by (output started at /home/lorem/public_html/clients/ipsum/wp-content/plugins/myplugin/test.php:504) in /home/lorem/public_html/clients/ipsum/wp-includes/pluggable.php on line 864 PHP Error notice Notice: Undefined variable: post_id in /home/lorem/public_html/clients/ipsum/wp-content/plugins/myplugin/test.php on line 18 $_REQUEST is a combination of a lot of … Read more

How can I make all gallery images to open in a new window?

(Update 04.05.2012: Include captions) Let’s start with a solution … There is no filter especially for gallery image links. There is also no filter for the gallery shortcode output. So we have to fake one: add_action( ‘after_setup_theme’, ‘wpse_50911_replace_img_shortcodes’ ); /** * Replace the default shortcode handlers. * * @return void */ function wpse_50911_replace_img_shortcodes() { remove_shortcode( … Read more

Restrict the number of images to upload per post

I won’t go into the code specifics right now, because I am not sure if you need me to. You essentially need to modify the SWFUpload JavaScript settings array to set the file_upload_limit to 1. Unfortunately I don’t believe SWFUpload allows you to change that settings variable after it has been inited, because it has … Read more

Pasting images removes class attribute

Instead of pasting into the Visual editor, switch to the html editor for pasting any kind of html, or using shortcodes. I’d recommend checking the “disable the visual editor” checkbox in your user profile. Then install Mark Jaquith’s Markdown on Save plugin for more readable formatting without the wysiwyg pitfalls.

Separate attachment images from post loop

The best way to assign images to a given post is to just upload them in the WordPress post editing/new post area. You can also delete images from there. With that said, here would be how you do that. You’re going to hook into wp_enqueue_script, and call wp_enqueue_script to add your gallery script to the … Read more

Change image link: wp_get_attachment_link

I think I’ve answered my own question sort of…. As I was using a child theme of Hybrid I activated the cleaner gallery extension in the functions.php file: add_theme_support( ‘cleaner-gallery’ ); Then, based on the topic here I created my own filter: add_filter( ‘cleaner_gallery_image’, ‘my_gallery_image’, 10, 4 ); function my_gallery_image( $image, $id, $attr, $instance ) … Read more

How to remove title attribute from gallery links and images

I’ve found a solution : // Remove &lt;img&gt; title attribute in // http://wordpress.org/support/topic/wp_get_attachment_image_attributes-filter-not-working function remove_img_title($atts) { unset($atts[‘title’]); return $atts; } add_filter(‘wp_get_attachment_image_attributes’,’remove_img_title’, 10, 4); // remove title attribute from &lt;a&gt; title attribute in // modified from this post : http://oikos.org.uk/2011/09/tech-notes-using-resized-images-in-wordpress-galleries-and-lightboxes/ function ah_get_attachment_link_filter( $content ) { $new_content = preg_replace(‘/title=\'(.*?)\”https://wordpress.stackexchange.com/”, ”, $content ); return $new_content; } add_filter(‘wp_get_attachment_link’, ‘ah_get_attachment_link_filter’, … Read more

Define WordPress image size in img tag

How about PHP Function getimagesize() <? $sImageurl = of_get_option(‘slideshow_1’); list($iWidthinpx, $iHeightinpx) = getimagesize($sImageurl); echo ‘<img src=”‘ . $sImageurl . ‘” width=”‘ . $iWidthinpx. ‘” height=”‘ . $iHeightinpx. ‘” alt=”#”/>’; ?> or if you know the attachment id instead of the attachment url you could use <? $aImagedata = wp_get_attachment_image_src($iAttachmentid, ‘my-image-size’, false); list($sImageurl, $iWidthinpx, $iHeightinpx) = … Read more

get post attachments of a particular size

The image attachment type is stored in the postmeta table in the _wp_attachment_metadata meta key. The data is serialized, so it can’t be filtered on. But you could use a meta_query in your query: $images = get_posts( array( ‘post_type’ => ‘attachment’, ‘orderby’ => ‘rand’, ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘_wp_attachment_metadata’, ‘value’ … Read more