Hi @mian117,
Making changes to plugin’s code (or to a third-party theme) is not a good WordPress development practice: the next time you update the plugin WordPress will replace your modified plugin files with the stock ones automatically, undoing all of your plugin modifications.
Instead, please use the built-in hooks that the plugin provides so you can make changes to it without having to modify its code – like so for example:
<?php
/**
* Renders an alternative thumbnail from a custom field
* if the post doesn't have a thumbnail.
*
* @author Hector Cabrera
* @see https://wordpress.org/support/topic/multiple-custom-fields-10/
*
* @param string $img_url The default 'No thumbnail' image URL
* @return string $img_url The (modified) 'No thumbnail' image URL
*/
function wpp_thumbnail_fallback( $img_url, $post_id ) {
// Post doesn't have a thumbnail so let's fallback
// to the custom field one
if ( ! has_post_thumbnail( $post_id ) ) {
// Get the image URL from your custom field here
// and then assign it to $img_url or return your URL
//
// eg. $img_url = get_post_meta( $post_id, 'MY_CUSTOM_FIELD_IMG_URL', true );
}
return $img_url;
}
add_filter( 'wpp_default_thumbnail_url', 'wpp_thumbnail_fallback', 10, 2 );
If you have any other questions don’t hesitate to ask, ok?
I’m impressed with this fast response. Thank You very much.
This solution solved the problem. I have tweaked it a bit to work as per my requirement for more than 1 custom field.
/**
* Renders an alternative thumbnail from a custom field
* if the post doesn't have a thumbnail.
*
* @author Hector Cabrera
* @see https://wordpress.org/support/topic/multiple-custom-fields-10/
*
* @param string $img_url The default 'No thumbnail' image URL
* @return string $img_url The (modified) 'No thumbnail' image URL
*/
function wpp_thumbnail_fallback( $img_url, $post_id ) {
// Post doesn't have a thumbnail so let's fallback
// to the custom field one
if ( ! has_post_thumbnail( $post_id ) ) {
// Get the image URL from your custom field here
// and then assign it to $img_url or return your URL
if( get_field('graphic_910x512', $post_id) ){
$image_url_linkedin = get_field('graphic_910x512', $post_id);
$img_url = $image_url_linkedin['url'];
}
else if( get_field('graphic_683x512', $post_id) ){
$image_url_linkedin = get_field('graphic_683x512', $post_id);
$img_url = $image_url_linkedin['url'];
}
else if( get_field('xxl_graphic', $post_id) ){
$image_url_linkedin = get_field('xxl_graphic', $post_id);
$img_url = $image_url_linkedin['url'];
}
}
return $img_url;
}
add_filter( 'wpp_default_thumbnail_url', 'wpp_thumbnail_fallback', 10, 2 );