Featured Image from Custom field value
-
I Want to display featured image from
bt_image_url
custom field if featured image is empty.I am using this code but its not working:
// Replace the default featured image with custom field image for blogger-template post type function bai_replace_featured_image_with_custom_field( $html, $post_id, $post_thumbnail_id, $size, $attr ) { // Check if current post is of blogger-template post type if ( get_post_type( $post_id ) === 'blogger-template' ) { $image_url = rwmb_get_value( 'bt_image_url', $post->ID ); $alt_text = 'Check Out ' . rwmb_get_value( 'bt_name', $post->ID ) . ' Premium Blogger Template'; // Check if the post has a featured image set already if ( empty( $html ) ) { $html = '<img src="' . esc_attr( $image_url ) . '" alt="' . esc_attr( $alt_text ) . '" />'; } } return $html; } add_filter( 'post_thumbnail_html', 'bai_replace_featured_image_with_custom_field', 10, 5 );
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Featured Image from Custom field value’ is closed to new replies.