Skip to content

Commit

Permalink
New smaller featured image size to fit layout. RICG for featured images.
Browse files Browse the repository at this point in the history
  • Loading branch information
mor10 committed Aug 10, 2017
1 parent 0065369 commit 6b6b3db
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions functions.php
Expand Up @@ -41,7 +41,7 @@ function kuhn_setup() {
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
add_image_size( 'kuhn-index', 1045, 600, true);
add_image_size( 'kuhn-index', 966, 555, true);

// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
Expand Down Expand Up @@ -161,31 +161,15 @@ function kuhn_resource_hints( $urls, $relation_type ) {
function kuhn_content_image_sizes_attr( $sizes, $size ) {
if ( is_singular() ) {
$width = $size[0];
if ( 720 <= $width ) {
if ( 610 <= $width ) {
$sizes = '(min-width: 990px) 720px, (min-width: 1300px) 610px, 95vw';
}
return $sizes;
}
}
add_filter( 'wp_calculate_image_sizes', 'kuhn_content_image_sizes_attr', 10, 2 );

/**
* Filter the `sizes` value in the header image markup.
*
* @origin Twenty Seventeen 1.0
*
* @param string $html The HTML image tag markup being filtered.
* @param object $header The custom header object returned by 'get_custom_header()'.
* @param array $attr Array of the attributes for the image tag.
* @return string The filtered header image HTML.
*/
function kuhn_header_image_tag( $html, $header, $attr ) {
if ( isset( $attr['sizes'] ) ) {
$html = str_replace( $attr['sizes'], '100vw', $html );
}
return $html;
}
add_filter( 'get_header_image_tag', 'kuhn_header_image_tag', 10, 3 );

/**
* Add custom image sizes attribute to enhance responsive image functionality
* for post thumbnails.
Expand All @@ -198,17 +182,16 @@ function kuhn_header_image_tag( $html, $header, $attr ) {
* @return string A source size value for use in a post thumbnail 'sizes' attribute.
*/
function kuhn_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( !is_singular() ) {
if ( is_active_sidebar( 'sidebar-1' ) ) {
$attr['sizes'] = '(max-width: 900px) 90vw, 800px';
} else {
$attr['sizes'] = '(max-width: 1000px) 90vw, 1000px';
}
if ( is_singular() ) {
$attr['sizes'] = '(min-width: 990px) 720px, (min-width: 1300px) 820px, 95vw';
} else {
$attr['sizes'] = '(min-width: 990px) 955px, (min-width: 1300px) 966px, 95vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'kuhn_post_thumbnail_sizes_attr', 10, 3 );


/**
* Register widget area.
*
Expand Down

0 comments on commit 6b6b3db

Please sign in to comment.