Changeset 42343 for trunk/src/wp-content/themes/twentyfifteen/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/twentyfifteen/functions.php
r41756 r42343 43 43 44 44 if ( ! function_exists( 'twentyfifteen_setup' ) ) : 45 /** 46 * Sets up theme defaults and registers support for various WordPress features. 47 * 48 * Note that this function is hooked into the after_setup_theme hook, which 49 * runs before the init hook. The init hook is too late for some features, such 50 * as indicating support for post thumbnails. 51 * 52 * @since Twenty Fifteen 1.0 53 */ 54 function twentyfifteen_setup() { 55 56 /* 57 * Make theme available for translation. 58 * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyfifteen 59 * If you're building a theme based on twentyfifteen, use a find and replace 60 * to change 'twentyfifteen' to the name of your theme in all the template files 45 /** 46 * Sets up theme defaults and registers support for various WordPress features. 47 * 48 * Note that this function is hooked into the after_setup_theme hook, which 49 * runs before the init hook. The init hook is too late for some features, such 50 * as indicating support for post thumbnails. 51 * 52 * @since Twenty Fifteen 1.0 61 53 */ 62 load_theme_textdomain( 'twentyfifteen' ); 63 64 // Add default posts and comments RSS feed links to head. 65 add_theme_support( 'automatic-feed-links' ); 66 67 /* 68 * Let WordPress manage the document title. 69 * By adding theme support, we declare that this theme does not use a 70 * hard-coded <title> tag in the document head, and expect WordPress to 71 * provide it for us. 72 */ 73 add_theme_support( 'title-tag' ); 74 75 /* 76 * Enable support for Post Thumbnails on posts and pages. 77 * 78 * See: https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails 79 */ 80 add_theme_support( 'post-thumbnails' ); 81 set_post_thumbnail_size( 825, 510, true ); 82 83 // This theme uses wp_nav_menu() in two locations. 84 register_nav_menus( array( 85 'primary' => __( 'Primary Menu', 'twentyfifteen' ), 86 'social' => __( 'Social Links Menu', 'twentyfifteen' ), 87 ) ); 88 89 /* 90 * Switch default core markup for search form, comment form, and comments 91 * to output valid HTML5. 92 */ 93 add_theme_support( 'html5', array( 94 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' 95 ) ); 96 97 /* 98 * Enable support for Post Formats. 99 * 100 * See: https://codex.wordpress.org/Post_Formats 101 */ 102 add_theme_support( 'post-formats', array( 103 'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat' 104 ) ); 105 106 /* 107 * Enable support for custom logo. 108 * 109 * @since Twenty Fifteen 1.5 110 */ 111 add_theme_support( 'custom-logo', array( 112 'height' => 248, 113 'width' => 248, 114 'flex-height' => true, 115 ) ); 116 117 $color_scheme = twentyfifteen_get_color_scheme(); 118 $default_color = trim( $color_scheme[0], '#' ); 119 120 // Setup the WordPress core custom background feature. 121 54 function twentyfifteen_setup() { 55 56 /* 57 * Make theme available for translation. 58 * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyfifteen 59 * If you're building a theme based on twentyfifteen, use a find and replace 60 * to change 'twentyfifteen' to the name of your theme in all the template files 61 */ 62 load_theme_textdomain( 'twentyfifteen' ); 63 64 // Add default posts and comments RSS feed links to head. 65 add_theme_support( 'automatic-feed-links' ); 66 67 /* 68 * Let WordPress manage the document title. 69 * By adding theme support, we declare that this theme does not use a 70 * hard-coded <title> tag in the document head, and expect WordPress to 71 * provide it for us. 72 */ 73 add_theme_support( 'title-tag' ); 74 75 /* 76 * Enable support for Post Thumbnails on posts and pages. 77 * 78 * See: https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails 79 */ 80 add_theme_support( 'post-thumbnails' ); 81 set_post_thumbnail_size( 825, 510, true ); 82 83 // This theme uses wp_nav_menu() in two locations. 84 register_nav_menus( 85 array( 86 'primary' => __( 'Primary Menu', 'twentyfifteen' ), 87 'social' => __( 'Social Links Menu', 'twentyfifteen' ), 88 ) 89 ); 90 91 /* 92 * Switch default core markup for search form, comment form, and comments 93 * to output valid HTML5. 94 */ 95 add_theme_support( 96 'html5', array( 97 'search-form', 98 'comment-form', 99 'comment-list', 100 'gallery', 101 'caption', 102 ) 103 ); 104 105 /* 106 * Enable support for Post Formats. 107 * 108 * See: https://codex.wordpress.org/Post_Formats 109 */ 110 add_theme_support( 111 'post-formats', array( 112 'aside', 113 'image', 114 'video', 115 'quote', 116 'link', 117 'gallery', 118 'status', 119 'audio', 120 'chat', 121 ) 122 ); 123 124 /* 125 * Enable support for custom logo. 126 * 127 * @since Twenty Fifteen 1.5 128 */ 129 add_theme_support( 130 'custom-logo', array( 131 'height' => 248, 132 'width' => 248, 133 'flex-height' => true, 134 ) 135 ); 136 137 $color_scheme = twentyfifteen_get_color_scheme(); 138 $default_color = trim( $color_scheme[0], '#' ); 139 140 // Setup the WordPress core custom background feature. 141 142 /** 143 * Filter Twenty Fifteen custom-header support arguments. 144 * 145 * @since Twenty Fifteen 1.0 146 * 147 * @param array $args { 148 * An array of custom-header support arguments. 149 * 150 * @type string $default-color Default color of the header. 151 * @type string $default-attachment Default attachment of the header. 152 * } 153 */ 154 add_theme_support( 155 'custom-background', apply_filters( 156 'twentyfifteen_custom_background_args', array( 157 'default-color' => $default_color, 158 'default-attachment' => 'fixed', 159 ) 160 ) 161 ); 162 163 /* 164 * This theme styles the visual editor to resemble the theme style, 165 * specifically font, colors, icons, and column width. 166 */ 167 add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', twentyfifteen_fonts_url() ) ); 168 169 // Indicate widget sidebars can use selective refresh in the Customizer. 170 add_theme_support( 'customize-selective-refresh-widgets' ); 171 } 172 endif; // twentyfifteen_setup 173 add_action( 'after_setup_theme', 'twentyfifteen_setup' ); 174 175 /** 176 * Register widget area. 177 * 178 * @since Twenty Fifteen 1.0 179 * 180 * @link https://codex.wordpress.org/Function_Reference/register_sidebar 181 */ 182 function twentyfifteen_widgets_init() { 183 register_sidebar( 184 array( 185 'name' => __( 'Widget Area', 'twentyfifteen' ), 186 'id' => 'sidebar-1', 187 'description' => __( 'Add widgets here to appear in your sidebar.', 'twentyfifteen' ), 188 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 189 'after_widget' => '</aside>', 190 'before_title' => '<h2 class="widget-title">', 191 'after_title' => '</h2>', 192 ) 193 ); 194 } 195 add_action( 'widgets_init', 'twentyfifteen_widgets_init' ); 196 197 if ( ! function_exists( 'twentyfifteen_fonts_url' ) ) : 122 198 /** 123 * Filter Twenty Fifteen custom-header support arguments.199 * Register Google fonts for Twenty Fifteen. 124 200 * 125 201 * @since Twenty Fifteen 1.0 126 202 * 127 * @param array $args { 128 * An array of custom-header support arguments. 129 * 130 * @type string $default-color Default color of the header. 131 * @type string $default-attachment Default attachment of the header. 132 * } 203 * @return string Google fonts URL for the theme. 133 204 */ 134 add_theme_support( 'custom-background', apply_filters( 'twentyfifteen_custom_background_args', array( 135 'default-color' => $default_color, 136 'default-attachment' => 'fixed', 137 ) ) ); 138 139 /* 140 * This theme styles the visual editor to resemble the theme style, 141 * specifically font, colors, icons, and column width. 142 */ 143 add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', twentyfifteen_fonts_url() ) ); 144 145 // Indicate widget sidebars can use selective refresh in the Customizer. 146 add_theme_support( 'customize-selective-refresh-widgets' ); 147 } 148 endif; // twentyfifteen_setup 149 add_action( 'after_setup_theme', 'twentyfifteen_setup' ); 150 151 /** 152 * Register widget area. 153 * 154 * @since Twenty Fifteen 1.0 155 * 156 * @link https://codex.wordpress.org/Function_Reference/register_sidebar 157 */ 158 function twentyfifteen_widgets_init() { 159 register_sidebar( array( 160 'name' => __( 'Widget Area', 'twentyfifteen' ), 161 'id' => 'sidebar-1', 162 'description' => __( 'Add widgets here to appear in your sidebar.', 'twentyfifteen' ), 163 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 164 'after_widget' => '</aside>', 165 'before_title' => '<h2 class="widget-title">', 166 'after_title' => '</h2>', 167 ) ); 168 } 169 add_action( 'widgets_init', 'twentyfifteen_widgets_init' ); 170 171 if ( ! function_exists( 'twentyfifteen_fonts_url' ) ) : 172 /** 173 * Register Google fonts for Twenty Fifteen. 174 * 175 * @since Twenty Fifteen 1.0 176 * 177 * @return string Google fonts URL for the theme. 178 */ 179 function twentyfifteen_fonts_url() { 180 $fonts_url = ''; 181 $fonts = array(); 182 $subsets = 'latin,latin-ext'; 183 184 /* 185 * Translators: If there are characters in your language that are not supported 186 * by Noto Sans, translate this to 'off'. Do not translate into your own language. 187 */ 188 if ( 'off' !== _x( 'on', 'Noto Sans font: on or off', 'twentyfifteen' ) ) { 189 $fonts[] = 'Noto Sans:400italic,700italic,400,700'; 190 } 191 192 /* 193 * Translators: If there are characters in your language that are not supported 194 * by Noto Serif, translate this to 'off'. Do not translate into your own language. 195 */ 196 if ( 'off' !== _x( 'on', 'Noto Serif font: on or off', 'twentyfifteen' ) ) { 197 $fonts[] = 'Noto Serif:400italic,700italic,400,700'; 198 } 199 200 /* 201 * Translators: If there are characters in your language that are not supported 202 * by Inconsolata, translate this to 'off'. Do not translate into your own language. 203 */ 204 if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentyfifteen' ) ) { 205 $fonts[] = 'Inconsolata:400,700'; 206 } 207 208 /* 209 * Translators: To add an additional character subset specific to your language, 210 * translate this to 'greek', 'cyrillic', 'devanagari' or 'vietnamese'. Do not translate into your own language. 211 */ 212 $subset = _x( 'no-subset', 'Add new subset (greek, cyrillic, devanagari, vietnamese)', 'twentyfifteen' ); 213 214 if ( 'cyrillic' == $subset ) { 215 $subsets .= ',cyrillic,cyrillic-ext'; 216 } elseif ( 'greek' == $subset ) { 217 $subsets .= ',greek,greek-ext'; 218 } elseif ( 'devanagari' == $subset ) { 219 $subsets .= ',devanagari'; 220 } elseif ( 'vietnamese' == $subset ) { 221 $subsets .= ',vietnamese'; 222 } 223 224 if ( $fonts ) { 225 $fonts_url = add_query_arg( array( 226 'family' => urlencode( implode( '|', $fonts ) ), 227 'subset' => urlencode( $subsets ), 228 ), 'https://fonts.googleapis.com/css' ); 229 } 230 231 return $fonts_url; 232 } 205 function twentyfifteen_fonts_url() { 206 $fonts_url = ''; 207 $fonts = array(); 208 $subsets = 'latin,latin-ext'; 209 210 /* 211 * Translators: If there are characters in your language that are not supported 212 * by Noto Sans, translate this to 'off'. Do not translate into your own language. 213 */ 214 if ( 'off' !== _x( 'on', 'Noto Sans font: on or off', 'twentyfifteen' ) ) { 215 $fonts[] = 'Noto Sans:400italic,700italic,400,700'; 216 } 217 218 /* 219 * Translators: If there are characters in your language that are not supported 220 * by Noto Serif, translate this to 'off'. Do not translate into your own language. 221 */ 222 if ( 'off' !== _x( 'on', 'Noto Serif font: on or off', 'twentyfifteen' ) ) { 223 $fonts[] = 'Noto Serif:400italic,700italic,400,700'; 224 } 225 226 /* 227 * Translators: If there are characters in your language that are not supported 228 * by Inconsolata, translate this to 'off'. Do not translate into your own language. 229 */ 230 if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentyfifteen' ) ) { 231 $fonts[] = 'Inconsolata:400,700'; 232 } 233 234 /* 235 * Translators: To add an additional character subset specific to your language, 236 * translate this to 'greek', 'cyrillic', 'devanagari' or 'vietnamese'. Do not translate into your own language. 237 */ 238 $subset = _x( 'no-subset', 'Add new subset (greek, cyrillic, devanagari, vietnamese)', 'twentyfifteen' ); 239 240 if ( 'cyrillic' == $subset ) { 241 $subsets .= ',cyrillic,cyrillic-ext'; 242 } elseif ( 'greek' == $subset ) { 243 $subsets .= ',greek,greek-ext'; 244 } elseif ( 'devanagari' == $subset ) { 245 $subsets .= ',devanagari'; 246 } elseif ( 'vietnamese' == $subset ) { 247 $subsets .= ',vietnamese'; 248 } 249 250 if ( $fonts ) { 251 $fonts_url = add_query_arg( 252 array( 253 'family' => urlencode( implode( '|', $fonts ) ), 254 'subset' => urlencode( $subsets ), 255 ), 'https://fonts.googleapis.com/css' 256 ); 257 } 258 259 return $fonts_url; 260 } 233 261 endif; 234 262 … … 279 307 280 308 wp_enqueue_script( 'twentyfifteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150330', true ); 281 wp_localize_script( 'twentyfifteen-script', 'screenReaderText', array( 282 'expand' => '<span class="screen-reader-text">' . __( 'expand child menu', 'twentyfifteen' ) . '</span>', 283 'collapse' => '<span class="screen-reader-text">' . __( 'collapse child menu', 'twentyfifteen' ) . '</span>', 284 ) ); 309 wp_localize_script( 310 'twentyfifteen-script', 'screenReaderText', array( 311 'expand' => '<span class="screen-reader-text">' . __( 'expand child menu', 'twentyfifteen' ) . '</span>', 312 'collapse' => '<span class="screen-reader-text">' . __( 'collapse child menu', 'twentyfifteen' ) . '</span>', 313 ) 314 ); 285 315 } 286 316 add_action( 'wp_enqueue_scripts', 'twentyfifteen_scripts' ); … … 331 361 } 332 362 333 if ( $previous && 363 if ( $previous && has_post_thumbnail( $previous->ID ) ) { 334 364 $prevthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $previous->ID ), 'post-thumbnail' ); 335 $css .= '365 $css .= ' 336 366 .post-navigation .nav-previous { background-image: url(' . esc_url( $prevthumb[0] ) . '); } 337 367 .post-navigation .nav-previous .post-title, .post-navigation .nav-previous a:hover .post-title, .post-navigation .nav-previous .meta-nav { color: #fff; } … … 342 372 if ( $next && has_post_thumbnail( $next->ID ) ) { 343 373 $nextthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $next->ID ), 'post-thumbnail' ); 344 $css .= '374 $css .= ' 345 375 .post-navigation .nav-next { background-image: url(' . esc_url( $nextthumb[0] ) . '); border-top: 0; } 346 376 .post-navigation .nav-next .post-title, .post-navigation .nav-next a:hover .post-title, .post-navigation .nav-next .meta-nav { color: #fff; }
Note: See TracChangeset
for help on using the changeset viewer.