We're merging with GenerateBlocks! Learn more here.

[Support request] filter to alter output

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support filter to alter output

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #18578
    Xavier
    Participant

    Hello There!

    I’d like to know if is there a filter like «generate_featured_image_output» in WP Show Posts so I could be able to customize and put conditions on the output of images but in the home page.
    I’ve already done so in the posts/archive pages but it doesn’t wor at the home.

    Thanks!

    #18590
    Tom
    Keymaster

    Hi there,

    WPSP doesn’t have a similar filter at the moment, unfortunately.

    What exactly are you trying to do? There may be another option.

    #18615
    Xavier
    Participant

    Hi Tom!

    Thanks very much for your quick answer.
    Well, I’ve used this code in the archive pages which check if an image file is loaded and if is so, uses it as the thumbnail img:

    function etdla_custom_featured_image( $output ) {
    	if ( get_post_meta( get_the_ID(), 'imatge_destacada_alternativa', true ) ) {
    		$foto_alt_id = get_post_meta( get_the_ID(), 'imatge_destacada_alternativa', true ) ;
    		$foto_alt_url = wp_get_attachment_url( $foto_alt_id );
    		$image_alt = get_post_meta($foto_alt_id, '_wp_attachment_image_alt', TRUE);
    		return '<div class="post-image">
    			<a href="'. get_the_permalink( get_the_ID() ) .'">
    			<img width="300" height="190" src="'.$foto_alt_url.'" class="attachment-300x190x1 size-300x190x1 wp-post-image" alt="'.$image_alt.'" itemprop="image" />
    			</a>
    			</div>';
      } else {
         return $output;
      }
    }
    add_filter( 'generate_featured_image_output', 'etdla_custom_featured_image');
    
    #18629
    Tom
    Keymaster

    You may be able to filter the WordPress featured image ID before it ever reaches the plugin or theme:

    add_filter( 'get_post_metadata', 'tu_override_featured_image_id', 100, 4 );
    
    function tu_override_featured_image_id( $metadata, $object_id, $meta_key, $single ) {
        if ( isset( $meta_key ) && 'thumbnail_id' == $meta_key ){
            remove_filter( 'get_post_metadata', 'tu_override_featured_image_id', 100 );
            $new_id = get_post_meta( $object_id, 'imatge_destacada_alternativa', true ) ;
            add_filter( 'tu_override_featured_image_id', 'getqtlangcustomfieldvalue', 100, 4 );
    
            if ( $new_id ) {
                $metadata = $new_id;
            }
        }
    
        return $metadata;
    }

    Not sure if it will work, but worth a shot.

    #18643
    Xavier
    Participant

    Hello again,
    Well, nice try, Thanks. I’ve been playing a while and found a couple of things:
    One: your code had two errors. The working one (errors in bold) is this:

    add_filter( 'get_post_metadata', 'tu_override_featured_image_id', 999, 4 );
    
    function tu_override_featured_image_id( $metadata, $object_id, $meta_key, $single ) {
    
    	if ( isset( $meta_key ) && '<strong>_thumbnail_id</strong>' == $meta_key ){
    		remove_filter( 'get_post_metadata', 'tu_override_featured_image_id', 100 );
    		$new_id = get_post_meta( $object_id, 'imatge_destacada_alternativa', true ) ;
    		add_filter( <strong>'get_post_metadata'</strong>, 'getqtlangcustomfieldvalue', 100, 4 );
    
    		if ( $new_id ) {
    			$metadata = $new_id;
    		}
    	}
    
    	return $metadata;
    }
    

    Two: Actually, this changes the featured image everywhere, while I need to swap it only in the «index» pages as in here:
    https://tempsarts.cat/seccio/didactica-de-lart/
    and in here ( which is the place I can’t… 😀 )
    https://tempsarts.cat/
    You can see the different thumbnails in the post ‘«Ferro i cànem» de Paco Ferrando‘.
    Any further idea?
    Again, thanks for your interest, Tom.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.