• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress a2z

WordPress a2z

WordPress Dynamic API Reference

  • Home
  • Plugins
  • Themes
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / twentysixteen_content_image_sizes_attr() – Add custom image sizes attribute to enhance responsive image functionality for content images

You appear to be a bot. Output may be restricted

Description

Add custom image sizes attribute to enhance responsive image functionality for content images

Usage

$string = twentysixteen_content_image_sizes_attr( $sizes, $size );

Parameters

$sizes
( string ) required – A source size value for use in a 'sizes' attribute.
$size
( array ) required – Image size. Accepts an array of width and height values in pixels (in that order).

Returns

string A source size value for use in a content image 'sizes' attribute.

Source

File name: twentysixteen/functions.php
Lines:

1 to 21 of 21
function twentysixteen_content_image_sizes_attr( $sizes, $size ) {
  $width = $size[0];

  if ( 840 <= $width ) {
    $sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
  }

  if ( 'page' === get_post_type() ) {
    if ( 840 > $width ) {
      $sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
    }
  } else {
    if ( 840 > $width && 600 <= $width ) {
      $sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px';
    } elseif ( 600 > $width ) {
      $sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
    }
  }

  return $sizes;
}
 

 View on Trac

Published: 25th November 2019 | Last updated: 25th November 2019

Primary Sidebar

Information

Function name: twentysixteen_content_image_sizes_attr
Plugin ref: Twenty Sixteen
Version: 2.8
Sourcefile: functions.php
File ref: functions.php
Deprecated?: No
API Letters: A,C,I,S,T

Footer

WordPress a2z
WordPress a2z
WordPress Dynamic API Reference
WordPress 6.1.1. PHP: 8.0.28
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  wp-a2z.org
© Copyright WordPress a2z 2014-2023. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites