Custom field as featured image caption

Here’s one way to inject the custom field as the featured image caption with help of the post_thumbnail_html filter: add_filter( ‘post_thumbnail_html’, function( $html, $post_id ) { if( $html && $caption = get_post_meta( $post_id, ‘wpcf-bildunterschrift’, true ) ) $html .= sprintf( ‘<p>%s</p>’, sanitize_text_field( $caption ) ); return $html; }, 10, 2 ); Hopefully you can adjust … Read more

Add valid XHTML closing img tags to WordPress galleries

As linked to from the comments on your question, the post_gallery filter should help you here. Unlike a lot of other hooks though, you can’t filter the output that comes through from WordPress; you can only provide your own alternative output. This is slightly annoying, and results in you needing to build the gallery from … Read more

Use default image as var

This is mostly a PHP general question about concatenating a function’s returned value with a (or many) string(s). The get_bloginfo function returns a string instead of echoing it directly. Thus you start off with: // First param value: stylesheet_directory // Using “template_url” also works unless you are using a child theme // In that case, … Read more

Why do I have blury images in WordPress

The filter you are using only stops jpeg compression. This does not prevent quality loss when resizing an image. Manually you would apply a sharpen filter afterwards to regain some crispyness in the image. WordPress doesn’t do that. However, WP does have the WP_Image_Editor class for image manipulation. It has some built-in methods, such as … Read more

Function to insert missing image size attributes into img tags

function replaceImageMeta( $imagename ) { preg_match_all(‘/(alt|title|src)=(“[^”]*”)/i’,$imagename, $img);//var_dump( str_replace(“\””, “” , ( $img[2][0] ) ) ); list($width, $height, $type, $attr) = getimagesize( str_replace(“\””, “” , ( $img[2][0] ) )); $imgname = str_replace(“\””, “” , ( $img[2][0] ) ); return sprintf(‘<img src=”https://wordpress.stackexchange.com/questions/235051/%s” width=”%dpx” height=”%dpx” >’, str_replace(“\””, “” , ( $img[2][0] ) ), $width, $height); } So call … Read more

How to display image in mail header using wp_mail()

The email header is not the same as the <head> of an HTML document (even if that document is an email). So the question shouldn’t be how to display an image in the email header because the answer is that you can’t. Second, the same thing holds true for an HTML document. The <head> section … Read more

Get image attachment to a post outside the loop?

try using get_attached_media function and your current $postID $images = get_attached_media( ‘image’, $postID ); this will return a WP_Post object. If you want to get the url, it’s located in the guid key of the object. Use a foreach loop to retrieve them all. foreach( $images as $image ){ $src[] = $image->guid; } To use … Read more