Prevent WordPress from cropping GIF files

Unsetting sizes can normally be done easily via intermediate_image_sizes_advanced hook. The only problem is, there is only the $sizes array available, so this sufficient for a general level, but not if you want to do this conditionally. The information needed to do it conditionally can be gathered with debug_backtrace – debug_backtrace is performance-wise somewhat expensive … Read more

wp_get_attachment_image_src() and custom sizes

You are misreading the Codex. wp_get_attachment_image_src() works just fine with custom image sizes. Proof of concept: // copied from the Codex // https://codex.wordpress.org/Function_Reference/add_image_size if ( function_exists( ‘add_image_size’ ) ) { add_image_size( ‘category-thumb’, 300, 9999 ); //300 pixels wide (and unlimited height) add_image_size( ‘homepage-thumb’, 220, 180, true ); //(cropped) } Add an image to the Library, … Read more

oEmbed, thumbnails and wordpress

Use the oembed_dataparse filter to modify the resulting HTML output by any given oembed call. Example: add_filter(‘oembed_dataparse’,’test’,10,3); function test($return, $data, $url) { if ($data->provider_name == ‘YouTube’) { return “<img src=”https://wordpress.stackexchange.com/questions/19500/{$data->thumbnail_url}”>”; } else return $return; } Then putting this in a post: Will give you a picture of Rick Astley instead of a flash video of … Read more

Featured Image of Video from oembed

I needed just this for a recent project, so here’s my plugin! The code should be self-explanatory, but if there are any questions ask away. <?php /** * Plugin Name: oEmbed Featured Image * Plugin URI: http://wordpress.stackexchange.com/q/70752/1685 * Description: Automatically set the featured image if an oEmbed-compatible embed is found in the post content. * … Read more

the_post_thumbnail with lazyload JQ plugin

If you want to apply lazyload to each attachment image, you can just add your hoot to wp_get_attachment_image_attributes filter: add_filter( ‘wp_get_attachment_image_attributes”https://wordpress.stackexchange.com/questions/54986/,”wpse8170_add_lazyload_to_attachment_image’, 10, 2 ); function wpse8170_add_lazyload_to_attachment_image( $attr, $attachment ) { $attr[‘data-original’] = $attr[‘src’]; $attr[‘src’] = “https://wordpress.stackexchange.com/questions/54986/grey.gif”; return $attr; } Or if you can use second approach: $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), “size” ); // … Read more

Display Category Thumbnail and links in Woo commerce

Have did some customization. This will help you show parent and child category images. You can later customize this code as per your requirements. $taxonomyName = “product_cat”; //This gets top layer terms only. This is done by setting parent to 0. $parent_terms = get_terms($taxonomyName, array(‘parent’ => 0, ‘orderby’ => ‘slug’, ‘hide_empty’ => false)); echo ‘<ul>’; … Read more