neilgee
7/7/2016 - 12:59 AM

Add Customizer Control for Adding Featured Image automatically to Posts/Pages - http://wpbeaches.com/add-featured-image-top-page-genesis/

Add Customizer Control for Adding Featured Image automatically to Posts/Pages - http://wpbeaches.com/add-featured-image-top-page-genesis/

<?php //<= dont add me in

// Add featured image on single post
add_action( 'genesis_entry_content', 'themeprefix_featured_image', 1 );
function themeprefix_featured_image() {

	$add_single_image = get_theme_mod( 'themeprefix_single_image_setting', true ); //sets the customizer setting to a variable

	$image = genesis_get_image( array( // more options here -> genesis/lib/functions/image.php
			'format'  => 'html',
			'size'    => 'large',// add in your image size large, medium or thumbnail - for custom see the post
			'context' => '',
			'attr'    => array ( 'class' => 'aligncenter' ), // set a default WP image class
			
		) );

	if ( is_singular() && ( true === $add_single_image ) ) {
		if ( $image ) {
			printf( '<div class="featured-image-class">%s</div>', $image ); // wraps the featured image in a div with css class you can control
		}
	}

}
<?php //<= dont add me in

// Add featured image on single post
add_action( 'genesis_entry_header', 'themeprefix_featured_image', 1 );
function themeprefix_featured_image() {
	$image = genesis_get_image( array( // more options here -> genesis/lib/functions/image.php
			'format'  => 'html',
			'size'    => 'large',// add in your image size large, medium or thumbnail - for custom see the post
			'context' => '',
			'attr'    => array ( 'class' => 'aligncenter' ), // set a default WP image class

		) );
	if ( is_singular()) {
		if ( $image ) {
			printf( '<div class="featured-image-class">%s</div>', $image ); // wraps the featured image in a div with css class you can control
		}
	}
}
<?php //<= dont add me in

add_action( 'customize_register', 'themeprefix_customizer_featured_image' );
 
function themeprefix_customizer_featured_image() {

	global $wp_customize;
	
	// Add featured image section to the Customizer
	$wp_customize->add_section(
	'themeprefix_single_image_section',
	array(
		'title'       => __( 'Post and Page Images', 'themeprefix' ),
		'description' => __( 'Choose if you would like to display the featured image above the content on single posts and pages.', 'themeprefix' ),
		'priority' => 200, // puts the customizer section lower down
	)
);

	// Add featured image setting to the Customizer
	$wp_customize->add_setting(
	'themeprefix_single_image_setting',
	array(
		'default'           => true, // set the option as enabled by default
		'capability'        => 'edit_theme_options',
	)
);

	$wp_customize->add_control(
	'themeprefix_single_image_setting',
	array(
		'section'   => 'themeprefix_single_image_section',
		'settings'  => 'themeprefix_single_image_setting',
		'label'     => __( 'Show featured image on posts and pages?', 'themeprefix' ),
		'type'      => 'checkbox'
	)
);

}