Image Scaling using get_the_post_thumbnail issue in WordPress

ALWAYS REGENERATE SOURCE SET ON IMAGE EDIT (New material, especially the custom function, follows conversation in comment thread.) The following function automatically regenerates a full source set after an image edit action. /** * ALWAYS REGENERATE FULL SOURCE SET AFTER EDITING IMAGE * answering StackExchange WordPress Development Question * see: https://wordpress.stackexchange.com/questions/288581/image-scaling-using-get-the-post-thumbnail-issue-in-wordpress/ * exploits code already … Read more

How do I detach images from posts?

If you view the Media Library in the list mode: /wp-admin/upload.php?mode=list then you will see the Attach/Detach links for each attachment. Each attachment can only be attached to a single parent through the post_parent field in the wp_posst table. Deleting an image from the post editor will not change the post_parent field to 0. Making … Read more

Replace image attributes for lazyload plugin (data-src)

instead of replacing the alt tag you could add-an-attribute-to-a-tag function add_lazyload($content) { $dom = new DOMDocument(); @$dom->loadHTML($content); foreach ($dom->getElementsByTagName(‘img’) as $node) { $oldsrc = $node->getAttribute(‘src’); $node->setAttribute(“data-original”, $oldsrc ); $newsrc=””.get_template_directory_uri().’/library/images/nothing.gif’; $node->setAttribute(“src”, $newsrc); } $newHtml = $dom->saveHtml(); return $newHtml; } note: i didn’t quite tested this code, so be careful 🙂

Applying automatic link class to images embedded to posts

You can run a filter on image_send_to_editor, the filter runs inside the get_image_send_to_editor function which is resposible for sending the link HTML that surrounds images sent to the editor. The filter can be found in core, in wp-admin/includes/media and is linked below for quick reference. core.trac.wordpress.org/browser/tags/3.1/wp-admin/includes/media.php

How to add image uploader to a custom widget?

Firstly, it is not recommended to use WP_PLUGIN_URL constant, instead use plugins_url() function. Second thing, it will not work when you put your files in the theme. You must put the necessary folder and file in the plugin if have to use this constant or function. Make sure, you have put correct path and you … Read more

Pb with responsive image sizes in WP 4.4

I handle the context like this: function wpse_216001_srcset() { // generate your Srcset here and return } function wpse_216001_sizes() { // generate your sizes attribute here and return } add_filter( ‘wp_calculate_image_sizes’, ‘wpse_216001_sizes’, 10 , 2 ); add_filter( ‘wp_calculate_image_srcset’, ‘wpse_216001_srcset’, 10 , 5); // call one of the standard WP image output functions here remove_filter( ‘wp_calculate_image_sizes’, … Read more

wp_get_attachment_image_src problem

Try using the Regenerate Thumbnails plugin, that will run through all your media and regenerate thumbnails according to the registered image sizes. Also note that that you’re getting the hight parameter as 226 because during add_image_size your third parameter said to not crop the image. Change that to true if you need cropping.

List most recent image uploads, but only for specific custom post type

Did you try adding a filter to get_posts. This isn’t tested, just a thought after a bit of searching : function my_filter( $query ) { if( is_home() ) //Example, if u want to display recent images on home { $query->set( ‘post_type’, array( ‘attachment’, ‘my_cpt’ ) ); } } add_filter( ‘pre_get_posts’, ‘my_filter’ ); EDIT : After … Read more

Validate alt text for attachments?

The code below will only run once whenever a file is uploaded. We keep an array ( $image_mimes ) of acceptable image-mimetypes We get the current attachment mime type We make sure what is given is indeed an image ( because we don’t need unnecessary postmeta cluttering our table ) We grab the title from … Read more