[Support request] Default / Fallback featured image

Home Forums Support [Support request] Default / Fallback featured image

Home Forums Support Default / Fallback featured image

Viewing 8 posts - 16 through 23 (of 23 total)
  • Author
    Posts
  • #510939
    Tom
    Lead Developer
    Lead Developer

    That plugin is using the post_thumbnail_html filter we tried above.

    We could try tweaking that function again:

    add_filter( 'post_thumbnail_html', 'tu_post_thumbnail_fallback', 20, 5 );
    function tu_post_thumbnail_fallback( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
        if ( empty( $post_thumbnail_id ) ) {
            $html = '<img src="URL TO YOUR FALLBACK IMAGE" alt="" />';
        }
    
        return $html;
    }
    #605343
    Dan

    Hi Tom,
    Wanted to know if there’s an update regarding this.

    Thanks
    Dan

    #605378
    Tom
    Lead Developer
    Lead Developer

    I assume my above tweak didn’t work?

    #605459
    Dan

    no, tried it again on a different site and it doesn’t show either.
    It’s like it’s ignoring either the filter or the function.

    #605743
    Tom
    Lead Developer
    Lead Developer

    I’ll put aside some time tomorrow to test this thoroughly – will be back with working code ๐Ÿ™‚

    #606225
    Tom
    Lead Developer
    Lead Developer

    Looking at this more. The code I would give you would be directly taken from the plugin I mentioned earlier, which seems like a bit of a waste.

    What’s wrong with using the plugin again exactly?

    #606317
    Dan

    Hi Tom
    Thanks for taking the time to look into this.
    I have 2 concerns:
    1. why isn’t the core function for detecting and placing a default featured image not working? is that a sign for maybe something else not functioning correctly?
    2. I usually prefer using vanilla code rather than a plugin for the obvious reasons.

    Thanks
    Dan

    #606476
    Tom
    Lead Developer
    Lead Developer

    1. GP checks for has_post_thumbnail(), which checks the post meta for an ID. Since that doesn’t exist (even if we filter the HTML), nothing is returned.

    2. A plugin is just code. That particular plugin is very small and only does a couple things. It’s also been updated recently. The plugin does 3 things:

    1. Adds a field for you to upload an image.
    2. Filters the post meta and adds the ID of that image.
    3. Filters the featured image HTML.

    So the code I would give you would be their code from #2 and #3. We can do that if you’d like, but I’m not sure I see the benefit. Not all plugins are evil ๐Ÿ˜‰

Viewing 8 posts - 16 through 23 (of 23 total)
  • You must be logged in to reply to this topic.