Archived topic
Customise featured image in single CPT
3 replies · Started by Alain Aubry on August 9, 2018
Hi
I want to modify the feature image options for a single CPT, like width, height, alignment, location, crop.
I found https://generatepress.com/forums/topic/hide-featured-image-in-single-cpt/ and https://docs.generatepress.com/article/adjusting-the-featured-images/#changing-the-featured-image-sizes-using-a-filter
I understand that it will possible with some filters, I tried:
add_filter( 'generate_blog_image_attributes','tu_variable_image_sizes' );
function tu_variable_image_sizes( $atts ) {
// Set up our conditional
if ( is_post_type_archive( 'colaborador' ) ) {
$atts[ 'width' ] = 400;
$atts[ 'height' ] = 400;
$atts[ 'crop' ] = true;
$atts[ 'single_post_image_position' ] = 'below-title';
$atts[ 'single_post_image_alignment' ] = 'left';
}
// Return our options
return $atts;
}
I got those values inspecting the customizer...
Thanks
Alain
Hi there,
You are on the right track for sizing options:
https://docs.generatepress.com/article/adjusting-the-featured-images/#changing-the-featured-image-sizes-using-a-filter
As for location, try this filter:
https://docs.generatepress.com/article/option_generate_blog_settings/
Let me know if this helps :)
Thanks Leo
You get me in track... so the parameters for single CPT are:
add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
if ( is_single() && 'colaborador' == get_post_type( get_the_ID() ) ) {
$options[ 'single_post_image' ] = true;
$options[ 'single_post_image_position' ] = 'below-title';
$options[ 'single_post_image_alignment' ] = 'left';
}
return $options;
}
Thanks
Alain
No problem :)