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

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

Using Image Sizes for Custom Post Types outside the Loop

You are doing wrong on this part the_post_thumbnail($page->ID, “my-non-working-size”); For the_post_thumbnail() you don’t need to pass post ID, you just have to pass size and attr. More Info – the_post_thumbnail() So try like this the_post_thumbnail(“my-non-working-size”); without passing post ID. Your markup messed up so I’m not sure your actual markup structure. Here is working example … Read more

Set featured image from custom field URL

Hook ‘acf/save_post’ after ACF saves the $_POST[‘acf’] data. Then check to see if the post has_post_thumbnail and set_post_thumbnail if it doesn’t. function save_acf_image_to_post_thumbnail( $post_id ) { $image = get_field( ‘fl_image’ ); if ( ! empty ( $image ) ) { if ( ! has_post_thumbnail( $post_id ) ) { $image_id = isset( $image[ ‘id’ ] ) … Read more