Site logo

Archived topic

Dynamic Hero image

3 replies · Started by Jonas on January 22, 2019

Viewing posts 1–4 of 4

Hi,

I have one custom post that I have a featured image in, but I would like to use that image as a featured image on a separate custom post. I would like to use that link as a featured image but can not seem to find a way to do it and where, programmatically. I could change them all but it’s a few and soon I am going to change the fetured image to download the link with an API call and I asume that that would be the same place where I would do it.

Any pointer would be appreciated,

Kru-X

Hi there,

Would the link to that featured image change dynamically? Or will it be static?

If so, you could try this:

add_filter( 'generate_page_hero_background_image_url', function( $image_url ) {
    if ( ! $image_url ) {
        $image_url = 'URL TO YOUR IMAGE';
    }

    return $image_url;
} );

That function would use your fallback image if no image exists for the post.

Let me know :)

Yea, it is dynamic as I have the post with the image as a relation to the one I would like to display it on, but anyway that filter would do it. I missed that one looking.

As usual, you are a guru and have the best support I have ever come across, thanks for that.

Kru-x

Thank you! Glad I could help :)

This archived topic is closed to new replies.