wp/wp-content/themes/twentyfifteen/functions.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    53  */
    53  */
    54 function twentyfifteen_setup() {
    54 function twentyfifteen_setup() {
    55 
    55 
    56 	/*
    56 	/*
    57 	 * Make theme available for translation.
    57 	 * Make theme available for translation.
    58 	 * Translations can be filed in the /languages/ directory.
    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
    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
    60 	 * to change 'twentyfifteen' to the name of your theme in all the template files
    61 	 */
    61 	 */
    62 	load_theme_textdomain( 'twentyfifteen', get_template_directory() . '/languages' );
    62 	load_theme_textdomain( 'twentyfifteen' );
    63 
    63 
    64 	// Add default posts and comments RSS feed links to head.
    64 	// Add default posts and comments RSS feed links to head.
    65 	add_theme_support( 'automatic-feed-links' );
    65 	add_theme_support( 'automatic-feed-links' );
    66 
    66 
    67 	/*
    67 	/*
   101 	 */
   101 	 */
   102 	add_theme_support( 'post-formats', array(
   102 	add_theme_support( 'post-formats', array(
   103 		'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat'
   103 		'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat'
   104 	) );
   104 	) );
   105 
   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 
   106 	$color_scheme  = twentyfifteen_get_color_scheme();
   117 	$color_scheme  = twentyfifteen_get_color_scheme();
   107 	$default_color = trim( $color_scheme[0], '#' );
   118 	$default_color = trim( $color_scheme[0], '#' );
   108 
   119 
   109 	// Setup the WordPress core custom background feature.
   120 	// Setup the WordPress core custom background feature.
       
   121 
       
   122 	/**
       
   123 	 * Filter Twenty Fifteen custom-header support arguments.
       
   124 	 *
       
   125 	 * @since Twenty Fifteen 1.0
       
   126 	 *
       
   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 	 * }
       
   133 	 */
   110 	add_theme_support( 'custom-background', apply_filters( 'twentyfifteen_custom_background_args', array(
   134 	add_theme_support( 'custom-background', apply_filters( 'twentyfifteen_custom_background_args', array(
   111 		'default-color'      => $default_color,
   135 		'default-color'      => $default_color,
   112 		'default-attachment' => 'fixed',
   136 		'default-attachment' => 'fixed',
   113 	) ) );
   137 	) ) );
   114 
   138 
   115 	/*
   139 	/*
   116 	 * This theme styles the visual editor to resemble the theme style,
   140 	 * This theme styles the visual editor to resemble the theme style,
   117 	 * specifically font, colors, icons, and column width.
   141 	 * specifically font, colors, icons, and column width.
   118 	 */
   142 	 */
   119 	add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', twentyfifteen_fonts_url() ) );
   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' );
   120 }
   147 }
   121 endif; // twentyfifteen_setup
   148 endif; // twentyfifteen_setup
   122 add_action( 'after_setup_theme', 'twentyfifteen_setup' );
   149 add_action( 'after_setup_theme', 'twentyfifteen_setup' );
   123 
   150 
   124 /**
   151 /**
   196 
   223 
   197 	if ( $fonts ) {
   224 	if ( $fonts ) {
   198 		$fonts_url = add_query_arg( array(
   225 		$fonts_url = add_query_arg( array(
   199 			'family' => urlencode( implode( '|', $fonts ) ),
   226 			'family' => urlencode( implode( '|', $fonts ) ),
   200 			'subset' => urlencode( $subsets ),
   227 			'subset' => urlencode( $subsets ),
   201 		), '//fonts.googleapis.com/css' );
   228 		), 'https://fonts.googleapis.com/css' );
   202 	}
   229 	}
   203 
   230 
   204 	return $fonts_url;
   231 	return $fonts_url;
   205 }
   232 }
   206 endif;
   233 endif;
   255 		'expand'   => '<span class="screen-reader-text">' . __( 'expand child menu', 'twentyfifteen' ) . '</span>',
   282 		'expand'   => '<span class="screen-reader-text">' . __( 'expand child menu', 'twentyfifteen' ) . '</span>',
   256 		'collapse' => '<span class="screen-reader-text">' . __( 'collapse child menu', 'twentyfifteen' ) . '</span>',
   283 		'collapse' => '<span class="screen-reader-text">' . __( 'collapse child menu', 'twentyfifteen' ) . '</span>',
   257 	) );
   284 	) );
   258 }
   285 }
   259 add_action( 'wp_enqueue_scripts', 'twentyfifteen_scripts' );
   286 add_action( 'wp_enqueue_scripts', 'twentyfifteen_scripts' );
       
   287 
       
   288 /**
       
   289  * Add preconnect for Google Fonts.
       
   290  *
       
   291  * @since Twenty Fifteen 1.7
       
   292  *
       
   293  * @param array   $urls          URLs to print for resource hints.
       
   294  * @param string  $relation_type The relation type the URLs are printed.
       
   295  * @return array URLs to print for resource hints.
       
   296  */
       
   297 function twentyfifteen_resource_hints( $urls, $relation_type ) {
       
   298 	if ( wp_style_is( 'twentyfifteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
       
   299 		if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
       
   300 			$urls[] = array(
       
   301 				'href' => 'https://fonts.gstatic.com',
       
   302 				'crossorigin',
       
   303 			);
       
   304 		} else {
       
   305 			$urls[] = 'https://fonts.gstatic.com';
       
   306 		}
       
   307 	}
       
   308 
       
   309 	return $urls;
       
   310 }
       
   311 add_filter( 'wp_resource_hints', 'twentyfifteen_resource_hints', 10, 2 );
   260 
   312 
   261 /**
   313 /**
   262  * Add featured image as background image to post navigation elements.
   314  * Add featured image as background image to post navigation elements.
   263  *
   315  *
   264  * @since Twenty Fifteen 1.0
   316  * @since Twenty Fifteen 1.0
   332 	return str_replace( 'class="search-submit"', 'class="search-submit screen-reader-text"', $html );
   384 	return str_replace( 'class="search-submit"', 'class="search-submit screen-reader-text"', $html );
   333 }
   385 }
   334 add_filter( 'get_search_form', 'twentyfifteen_search_form_modify' );
   386 add_filter( 'get_search_form', 'twentyfifteen_search_form_modify' );
   335 
   387 
   336 /**
   388 /**
       
   389  * Modifies tag cloud widget arguments to display all tags in the same font size
       
   390  * and use list format for better accessibility.
       
   391  *
       
   392  * @since Twenty Fifteen 1.9
       
   393  *
       
   394  * @param array $args Arguments for tag cloud widget.
       
   395  * @return array The filtered arguments for tag cloud widget.
       
   396  */
       
   397 function twentyfifteen_widget_tag_cloud_args( $args ) {
       
   398 	$args['largest']  = 22;
       
   399 	$args['smallest'] = 8;
       
   400 	$args['unit']     = 'pt';
       
   401 	$args['format']   = 'list';
       
   402 
       
   403 	return $args;
       
   404 }
       
   405 add_filter( 'widget_tag_cloud_args', 'twentyfifteen_widget_tag_cloud_args' );
       
   406 
       
   407 
       
   408 /**
   337  * Implement the Custom Header feature.
   409  * Implement the Custom Header feature.
   338  *
   410  *
   339  * @since Twenty Fifteen 1.0
   411  * @since Twenty Fifteen 1.0
   340  */
   412  */
   341 require get_template_directory() . '/inc/custom-header.php';
   413 require get_template_directory() . '/inc/custom-header.php';