Wrap all post images inside a div element

Try using PHP’s regular expression find/replace function—preg_replace()—in a filter on the the_content hook. function breezer_addDivToImage( $content ) { // A regular expression of what to look for. $pattern = ‘/(<img([^>]*)>)/i’; // What to replace it with. $1 refers to the content in the first ‘capture group’, in parentheses above $replacement=”<div class=”myphoto”>$1</div>”; // run preg_replace() on … Read more

Use Filename for Alt and Title Tags

The alt tag already takes the filename but if for some reason you need to replace hyphens with spaces and include a duplicate title of the alt tag you can do something like: function wpse_120228_seomadness($html, $id, $caption, $title, $align, $url, $size, $alt) { $alttitle = str_replace(‘-‘, ‘ ‘, $alt); $img = get_image_tag($id, $alttitle, $alttitle, $align, … Read more

Rename attachments during upload

You can try to replace $arr[‘name’] = $post_slug . ‘-‘ . $random_number . ‘.jpg’; with $arr[‘name’] = $post_slug . ‘-‘ . $arr[‘name’]; to get the file format [post_slug]-[original_filename].ext. Update: Here is an example of the $arr structure for an image with the filename car.png : Array ( [name] => car.png [type] => image/png [tmp_name] => … Read more

get_children – wp_get_attachment_image

You could Limit the output to 1 like this but this is not a solution, only a workaround: $args = array(‘post_parent’ => get_the_ID(), ‘numberposts’ => 1, ‘order’ => ‘ASC’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’ ); $images = get_children( $args ); if ($images) { foreach ($images as $image) { echo wp_get_attachment_image($image->ID, ‘full’); } } Have … Read more

How to extract images of post and pages excluding header and logo image in wordpress?

I believe this will get you all of your attachments: $q = new WP_Query( array( ‘post_type’=>’attachment’, ‘post_status’=>’inherit’ ) ); var_dump($q); You could further restrict that by adding other parameters, for example, ‘post_mime_type’ => ‘image’ would restrict only to images. That will return all images though, not just the ones attached to posts. What you want … Read more

Adjusting caption below single post image

Override The Image Caption With Image Title And Description Here’s a way to override the caption with the image title and image description, with a demo plugin. Let’s assume we have uploaded this image: Then we insert it into the editor with the following: Before: Without our plugin activated it will display as: After: With … Read more