Skip to content
This repository has been archived by the owner on May 9, 2019. It is now read-only.

Add filter for $post_thumbnail_id to replace with default image #796

Open
claytoncollie opened this issue Oct 4, 2018 · 1 comment
Open

Comments

@claytoncollie
Copy link

claytoncollie commented Oct 4, 2018

What did you expect to happen?

My post type, People, is heavily driven by the featured image. When indexing post objects without a featured image, my front end view is thrown off. There is a row of 4-5 objects and 1 doesn't have an image. Looks bad. I created a Customizer option that holds the default headshot image ID that I would like to use when a featured image is not present.

Under Aglolia Utils, line 94 could have a filter that defaults to the thumbnail ID but allow me to pass another ID for Algolia to index.

$post_thumbnail_id = apply_filters( 'algolia_post_thumbnail_id', get_post_thumbnail_id( (int) $post_id ), $post_id );

Then my filter would look like this.

/**
 * When a featured image is not present, use another attachment ID provided by database option
 *
 * @param int $id Post thumbnail ID.
 * @param int $post_id Post ID.
 * 
 * @return int
 */
function prefix_fallback_for_post_thumbnail_id( $id, $post_id ) {
	
	if ( ! has_post_thumbnail( $post_id ) ) {
		$id = intval( get_option( 'default-headshot' ) );
	} else {
		$id = get_post_thumbnail_id( (int) $post_id );
	}

	return $id;
}`


Is it possible to add this filter?
@alishanster
Copy link

alishanster commented Oct 8, 2018

Hello! any updates on this? I am also interested in applying default thumbnail images if posts don't have a real one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants