Hi Grzegorz,
That’s correct! Since TSF 4.0, we use generators for images. Via the mere two filters we provide, you can make the generator do anything your heart desires, but it requires a bit of learning–once you understand how it works, a whole new world of programming with PHP opens ??
Are you referring to this snippet, here? https://www.ads-software.com/support/topic/wrong-image-used-and-two-other-remarks/#post-7157603
I think you can use the filter described here as-is. But, you’ll need to unset $params['cbs']['content']
, and append your custom callback to $params['cbs']
(the example already does the latter). The custom callback needs to yield the URL and ID of the image of your choosing.
In short, you’ll need to change:
$params['cbs']['custom'] = 'my_tsf_custom_singular_image_generator';
To:
unset( $params['cbs']['content'] );
$params['cbs']['custom'] = 'my_tsf_custom_singular_image_generator';
Aside: If you wish to retain the TSF-implemented content
callback, but wish to put in your custom callback right before that, please refer to this StackOverflow answer. It’s a bit cumbersome in PHP… we may want to implement “priorities” to work around this easily.
The callback function will look a bit like this (based on the comment you made earlier):
function my_tsf_custom_singular_image_generator( $args = null, $size = 'full' ) {
$post_id = isset( $args['id'] ) ? $args['id'] : the_seo_framework()->get_the_real_ID();
$args = [
'numberposts' => 1,
'order' => 'ASC',
'post_mime_type' => 'image',
'post_parent' => $post_id,
'post_type' => 'attachment',
'no_found_rows' => true,
];
$img = array_shift( get_posts( $args ) )->guid ?? '';
if ( ! $img ) {
$img = home_url( '/default-image.jpg' );
}
yield [
'url' => $img,
'id' => 0,
];
}
This is the amalgamated snippet: https://gist.github.com/sybrew/2f4e1fc1b5814fe813328009520a322c