ControlledChaos
8/8/2016 - 11:50 PM

Set default add image & create gallery links in WordPress.

Set default add image & create gallery links in WordPress.

<?php
/*
 * Single image links
 */

function ccd_default_image_link() {
	$image_set = get_option( 'image_default_link_type' );
	
	if ( $image_set !== 'file' ) { // Could be 'none'
		update_option( 'image_default_link_type', 'file' );
	}
}
add_action( 'admin_init', 'ccd_default_image_link', 10 );

?>
<?php
/*
 * Gallery image links
 */

function ccd_default_gallery_link( $settings ) {
	$settings['galleryDefaults']['link'] = 'file';
	
	return $settings;
}
add_filter( 'media_view_settings', 'ccd_default_gallery_link', 10 );

?>

Default Image Links

WordPress Snippet

Choose the default link when adding single images and image galleries to a post.