Rename image during upload using date and time stamp?

You could e.g. check the filename and extension from the pathinfo, after your custom sanitization. Example: If the filename is empty and extension non-empty, then add the formatted current time as the filename part: $info = pathinfo( $file[‘name’] ); if( empty( $info[‘filename’] ) && ! empty( $info[‘extension’] ) ) $file[‘name’] = sprintf( ‘%s.%s’, current_time( ‘Y-m-d-H-i-s’ … Read more

Insert width & height attributes to all images displayed on each page

Tested and confirmed that this works: add_filter( ‘the_content’, ‘add_image_dimensions’ ); function add_image_dimensions( $content ) { preg_match_all( ‘/<img[^>]+>/i’, $content, $images); if (count($images) < 1) return $content; foreach ($images[0] as $image) { preg_match_all( ‘/(alt|title|src|width|class|id|height)=(“[^”]*”)/i’, $image, $img ); if ( !in_array( ‘src’, $img[1] ) ) continue; if ( !in_array( ‘width’, $img[1] ) || !in_array( ‘height’, $img[1] ) ) … Read more

Disabling post images for not logged in users

You can use PHP strip_tags and hook to the_content filter by checking if user is logged in. add this to your functions.php file add_filter( ‘the_content’, ‘wpse_remove_img’ ); function wpse_remove_img( $content ){ if( ! is_user_logged_in() ){ // You need to specify which tag you want to keep here it’s p, a, h2,span, div. // Adjust accordingly … Read more

New image size option not showing

You need to register the image size first using add_image_size(), for example: add_action( ‘after_setup_theme’, ‘cyb_add_image_sizes’ ); function cyb_add_image_sizes() { add_image_size( ‘my-image-size-name’, 120, 120, true ); } Then, you can use the image_size_names_choose filter (you have misspelled it with image_size_names_chooser): add_filter( ‘image_size_names_choose’, ‘rudr_new_image_sizes’ ); function rudr_new_image_sizes( $sizes ) { $addsizes = array( “my-image-size-name” => ‘Misha size’ … Read more

Add data attribute to a gallery link?

This solution will add the data-fancybox=”group” to gallery links produced by the default shortcode. This has been tested and works regardless of whether themes have HTML5 theme support enabled for galleries or not. The solution works by using the post_gallery filter to gain access to the gallery shortcode’s output. From there, the HTML is parsed … Read more

Responsive Images – Add srcset attributes to custom Images Function

I think wp_get_attachment_srcset() is what you are looking for. $srcset = wp_get_attachment_image_srcset( $image[‘id’], array( 100, 100 ) ); Now you can escape the HTML and use it in your code. <img src=”https://wordpress.stackexchange.com/questions/276972/PATH HERE” srcset=”https://wordpress.stackexchange.com/<?php echo esc_attr( $srcset ); ?>”>

Sidebar slideshow widget [closed]

If your just going to be showing images jQuery Cycle is the way to go. It is very light and you simply call the js in your theme then wrap your images in a div ie: <div class=”pics”> <img src=”https://wordpress.stackexchange.com/questions/1807/images/beach1.jpg” width=”200″ height=”200″ /> <img src=”images/beach2.jpg” width=”200″ height=”200″ /> <img src=”images/beach3.jpg” width=”200″ height=”200″ /> </div> Then … Read more

extract post image to be featured images

if the image is inserted (attached) into the post and not a external link: function get_my_thumbnail($post_id, $size, $attr=””){ // check of featured image first $t = get_post_thumbnail_id($post_id); // no featured image set, check post attachments if(empty($t)){ $attachments = get_children(array( ‘post_parent’ => $post_id, ‘post_status’ => ‘inherit’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘order’ => ‘ASC’, ‘orderby’ … Read more