Changeset 42343 for trunk/src/wp-content/themes/twentysixteen/functions.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentysixteen/functions.php
r41756 r42343 34 34 35 35 if ( ! function_exists( 'twentysixteen_setup' ) ) : 36 /** 37 * Sets up theme defaults and registers support for various WordPress features. 38 * 39 * Note that this function is hooked into the after_setup_theme hook, which 40 * runs before the init hook. The init hook is too late for some features, such 41 * as indicating support for post thumbnails. 42 * 43 * Create your own twentysixteen_setup() function to override in a child theme. 44 * 45 * @since Twenty Sixteen 1.0 46 */ 47 function twentysixteen_setup() { 48 /* 49 * Make theme available for translation. 50 * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentysixteen 51 * If you're building a theme based on Twenty Sixteen, use a find and replace 52 * to change 'twentysixteen' to the name of your theme in all the template files 36 /** 37 * Sets up theme defaults and registers support for various WordPress features. 38 * 39 * Note that this function is hooked into the after_setup_theme hook, which 40 * runs before the init hook. The init hook is too late for some features, such 41 * as indicating support for post thumbnails. 42 * 43 * Create your own twentysixteen_setup() function to override in a child theme. 44 * 45 * @since Twenty Sixteen 1.0 53 46 */ 54 load_theme_textdomain( 'twentysixteen' ); 55 56 // Add default posts and comments RSS feed links to head. 57 add_theme_support( 'automatic-feed-links' ); 58 59 /* 60 * Let WordPress manage the document title. 61 * By adding theme support, we declare that this theme does not use a 62 * hard-coded <title> tag in the document head, and expect WordPress to 63 * provide it for us. 64 */ 65 add_theme_support( 'title-tag' ); 66 67 /* 68 * Enable support for custom logo. 69 * 70 * @since Twenty Sixteen 1.2 71 */ 72 add_theme_support( 'custom-logo', array( 73 'height' => 240, 74 'width' => 240, 75 'flex-height' => true, 76 ) ); 77 78 /* 79 * Enable support for Post Thumbnails on posts and pages. 80 * 81 * @link https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails 82 */ 83 add_theme_support( 'post-thumbnails' ); 84 set_post_thumbnail_size( 1200, 9999 ); 85 86 // This theme uses wp_nav_menu() in two locations. 87 register_nav_menus( array( 88 'primary' => __( 'Primary Menu', 'twentysixteen' ), 89 'social' => __( 'Social Links Menu', 'twentysixteen' ), 90 ) ); 91 92 /* 93 * Switch default core markup for search form, comment form, and comments 94 * to output valid HTML5. 95 */ 96 add_theme_support( 'html5', array( 97 'search-form', 98 'comment-form', 99 'comment-list', 100 'gallery', 101 'caption', 102 ) ); 103 104 /* 105 * Enable support for Post Formats. 106 * 107 * See: https://codex.wordpress.org/Post_Formats 108 */ 109 add_theme_support( 'post-formats', array( 110 'aside', 111 'image', 112 'video', 113 'quote', 114 'link', 115 'gallery', 116 'status', 117 'audio', 118 'chat', 119 ) ); 120 121 /* 122 * This theme styles the visual editor to resemble the theme style, 123 * specifically font, colors, icons, and column width. 124 */ 125 add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) ); 126 127 // Indicate widget sidebars can use selective refresh in the Customizer. 128 add_theme_support( 'customize-selective-refresh-widgets' ); 129 } 47 function twentysixteen_setup() { 48 /* 49 * Make theme available for translation. 50 * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentysixteen 51 * If you're building a theme based on Twenty Sixteen, use a find and replace 52 * to change 'twentysixteen' to the name of your theme in all the template files 53 */ 54 load_theme_textdomain( 'twentysixteen' ); 55 56 // Add default posts and comments RSS feed links to head. 57 add_theme_support( 'automatic-feed-links' ); 58 59 /* 60 * Let WordPress manage the document title. 61 * By adding theme support, we declare that this theme does not use a 62 * hard-coded <title> tag in the document head, and expect WordPress to 63 * provide it for us. 64 */ 65 add_theme_support( 'title-tag' ); 66 67 /* 68 * Enable support for custom logo. 69 * 70 * @since Twenty Sixteen 1.2 71 */ 72 add_theme_support( 73 'custom-logo', array( 74 'height' => 240, 75 'width' => 240, 76 'flex-height' => true, 77 ) 78 ); 79 80 /* 81 * Enable support for Post Thumbnails on posts and pages. 82 * 83 * @link https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails 84 */ 85 add_theme_support( 'post-thumbnails' ); 86 set_post_thumbnail_size( 1200, 9999 ); 87 88 // This theme uses wp_nav_menu() in two locations. 89 register_nav_menus( 90 array( 91 'primary' => __( 'Primary Menu', 'twentysixteen' ), 92 'social' => __( 'Social Links Menu', 'twentysixteen' ), 93 ) 94 ); 95 96 /* 97 * Switch default core markup for search form, comment form, and comments 98 * to output valid HTML5. 99 */ 100 add_theme_support( 101 'html5', array( 102 'search-form', 103 'comment-form', 104 'comment-list', 105 'gallery', 106 'caption', 107 ) 108 ); 109 110 /* 111 * Enable support for Post Formats. 112 * 113 * See: https://codex.wordpress.org/Post_Formats 114 */ 115 add_theme_support( 116 'post-formats', array( 117 'aside', 118 'image', 119 'video', 120 'quote', 121 'link', 122 'gallery', 123 'status', 124 'audio', 125 'chat', 126 ) 127 ); 128 129 /* 130 * This theme styles the visual editor to resemble the theme style, 131 * specifically font, colors, icons, and column width. 132 */ 133 add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) ); 134 135 // Indicate widget sidebars can use selective refresh in the Customizer. 136 add_theme_support( 'customize-selective-refresh-widgets' ); 137 } 130 138 endif; // twentysixteen_setup 131 139 add_action( 'after_setup_theme', 'twentysixteen_setup' ); … … 153 161 */ 154 162 function twentysixteen_widgets_init() { 155 register_sidebar( array( 156 'name' => __( 'Sidebar', 'twentysixteen' ), 157 'id' => 'sidebar-1', 158 'description' => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ), 159 'before_widget' => '<section id="%1$s" class="widget %2$s">', 160 'after_widget' => '</section>', 161 'before_title' => '<h2 class="widget-title">', 162 'after_title' => '</h2>', 163 ) ); 164 165 register_sidebar( array( 166 'name' => __( 'Content Bottom 1', 'twentysixteen' ), 167 'id' => 'sidebar-2', 168 'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ), 169 'before_widget' => '<section id="%1$s" class="widget %2$s">', 170 'after_widget' => '</section>', 171 'before_title' => '<h2 class="widget-title">', 172 'after_title' => '</h2>', 173 ) ); 174 175 register_sidebar( array( 176 'name' => __( 'Content Bottom 2', 'twentysixteen' ), 177 'id' => 'sidebar-3', 178 'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ), 179 'before_widget' => '<section id="%1$s" class="widget %2$s">', 180 'after_widget' => '</section>', 181 'before_title' => '<h2 class="widget-title">', 182 'after_title' => '</h2>', 183 ) ); 163 register_sidebar( 164 array( 165 'name' => __( 'Sidebar', 'twentysixteen' ), 166 'id' => 'sidebar-1', 167 'description' => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ), 168 'before_widget' => '<section id="%1$s" class="widget %2$s">', 169 'after_widget' => '</section>', 170 'before_title' => '<h2 class="widget-title">', 171 'after_title' => '</h2>', 172 ) 173 ); 174 175 register_sidebar( 176 array( 177 'name' => __( 'Content Bottom 1', 'twentysixteen' ), 178 'id' => 'sidebar-2', 179 'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ), 180 'before_widget' => '<section id="%1$s" class="widget %2$s">', 181 'after_widget' => '</section>', 182 'before_title' => '<h2 class="widget-title">', 183 'after_title' => '</h2>', 184 ) 185 ); 186 187 register_sidebar( 188 array( 189 'name' => __( 'Content Bottom 2', 'twentysixteen' ), 190 'id' => 'sidebar-3', 191 'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ), 192 'before_widget' => '<section id="%1$s" class="widget %2$s">', 193 'after_widget' => '</section>', 194 'before_title' => '<h2 class="widget-title">', 195 'after_title' => '</h2>', 196 ) 197 ); 184 198 } 185 199 add_action( 'widgets_init', 'twentysixteen_widgets_init' ); 186 200 187 201 if ( ! function_exists( 'twentysixteen_fonts_url' ) ) : 188 /** 189 * Register Google fonts for Twenty Sixteen. 190 * 191 * Create your own twentysixteen_fonts_url() function to override in a child theme. 192 * 193 * @since Twenty Sixteen 1.0 194 * 195 * @return string Google fonts URL for the theme. 196 */ 197 function twentysixteen_fonts_url() { 198 $fonts_url = ''; 199 $fonts = array(); 200 $subsets = 'latin,latin-ext'; 201 202 /* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */ 203 if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'twentysixteen' ) ) { 204 $fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic'; 205 } 206 207 /* translators: If there are characters in your language that are not supported by Montserrat, translate this to 'off'. Do not translate into your own language. */ 208 if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'twentysixteen' ) ) { 209 $fonts[] = 'Montserrat:400,700'; 210 } 211 212 /* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */ 213 if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentysixteen' ) ) { 214 $fonts[] = 'Inconsolata:400'; 215 } 216 217 if ( $fonts ) { 218 $fonts_url = add_query_arg( array( 219 'family' => urlencode( implode( '|', $fonts ) ), 220 'subset' => urlencode( $subsets ), 221 ), 'https://fonts.googleapis.com/css' ); 222 } 223 224 return $fonts_url; 225 } 202 /** 203 * Register Google fonts for Twenty Sixteen. 204 * 205 * Create your own twentysixteen_fonts_url() function to override in a child theme. 206 * 207 * @since Twenty Sixteen 1.0 208 * 209 * @return string Google fonts URL for the theme. 210 */ 211 function twentysixteen_fonts_url() { 212 $fonts_url = ''; 213 $fonts = array(); 214 $subsets = 'latin,latin-ext'; 215 216 /* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */ 217 if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'twentysixteen' ) ) { 218 $fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic'; 219 } 220 221 /* translators: If there are characters in your language that are not supported by Montserrat, translate this to 'off'. Do not translate into your own language. */ 222 if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'twentysixteen' ) ) { 223 $fonts[] = 'Montserrat:400,700'; 224 } 225 226 /* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */ 227 if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentysixteen' ) ) { 228 $fonts[] = 'Inconsolata:400'; 229 } 230 231 if ( $fonts ) { 232 $fonts_url = add_query_arg( 233 array( 234 'family' => urlencode( implode( '|', $fonts ) ), 235 'subset' => urlencode( $subsets ), 236 ), 'https://fonts.googleapis.com/css' 237 ); 238 } 239 240 return $fonts_url; 241 } 226 242 endif; 227 243 … … 281 297 wp_enqueue_script( 'twentysixteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20160816', true ); 282 298 283 wp_localize_script( 'twentysixteen-script', 'screenReaderText', array( 284 'expand' => __( 'expand child menu', 'twentysixteen' ), 285 'collapse' => __( 'collapse child menu', 'twentysixteen' ), 286 ) ); 299 wp_localize_script( 300 'twentysixteen-script', 'screenReaderText', array( 301 'expand' => __( 'expand child menu', 'twentysixteen' ), 302 'collapse' => __( 'collapse child menu', 'twentysixteen' ), 303 ) 304 ); 287 305 } 288 306 add_action( 'wp_enqueue_scripts', 'twentysixteen_scripts' ); … … 334 352 335 353 if ( strlen( $color ) === 3 ) { 336 $r = hexdec( substr( $color, 0, 1 ) .substr( $color, 0, 1 ) );337 $g = hexdec( substr( $color, 1, 1 ) .substr( $color, 1, 1 ) );338 $b = hexdec( substr( $color, 2, 1 ) .substr( $color, 2, 1 ) );339 } else 354 $r = hexdec( substr( $color, 0, 1 ) . substr( $color, 0, 1 ) ); 355 $g = hexdec( substr( $color, 1, 1 ) . substr( $color, 1, 1 ) ); 356 $b = hexdec( substr( $color, 2, 1 ) . substr( $color, 2, 1 ) ); 357 } elseif ( strlen( $color ) === 6 ) { 340 358 $r = hexdec( substr( $color, 0, 2 ) ); 341 359 $g = hexdec( substr( $color, 2, 2 ) ); … … 345 363 } 346 364 347 return array( 'red' => $r, 'green' => $g, 'blue' => $b ); 365 return array( 366 'red' => $r, 367 'green' => $g, 368 'blue' => $b, 369 ); 348 370 } 349 371 … … 390 412 return $sizes; 391 413 } 392 add_filter( 'wp_calculate_image_sizes', 'twentysixteen_content_image_sizes_attr', 10 414 add_filter( 'wp_calculate_image_sizes', 'twentysixteen_content_image_sizes_attr', 10, 2 ); 393 415 394 416 /** … … 413 435 return $attr; 414 436 } 415 add_filter( 'wp_get_attachment_image_attributes', 'twentysixteen_post_thumbnail_sizes_attr', 10 437 add_filter( 'wp_get_attachment_image_attributes', 'twentysixteen_post_thumbnail_sizes_attr', 10, 3 ); 416 438 417 439 /** … … 428 450 $args['smallest'] = 1; 429 451 $args['unit'] = 'em'; 430 $args['format'] = 'list'; 452 $args['format'] = 'list'; 431 453 432 454 return $args;
Note: See TracChangeset
for help on using the changeset viewer.