wp/wp-content/themes/twentythirteen/functions.php
changeset 10 372f2766ea20
parent 7 cf61fcea0001
equal deleted inserted replaced
9:177826044cd9 10:372f2766ea20
     4  *
     4  *
     5  * Sets up the theme and provides some helper functions, which are used in the
     5  * Sets up the theme and provides some helper functions, which are used in the
     6  * theme as custom template tags. Others are attached to action and filter
     6  * theme as custom template tags. Others are attached to action and filter
     7  * hooks in WordPress to change core functionality.
     7  * hooks in WordPress to change core functionality.
     8  *
     8  *
     9  * When using a child theme (see https://codex.wordpress.org/Theme_Development
     9  * When using a child theme you can override certain functions (those wrapped
    10  * and https://codex.wordpress.org/Child_Themes), you can override certain
    10  * in a function_exists() call) by defining them first in your child theme's
    11  * functions (those wrapped in a function_exists() call) by defining them first
    11  * functions.php file. The child theme's functions.php file is included before
    12  * in your child theme's functions.php file. The child theme's functions.php
    12  * the parent theme's file, so the child theme functions would be used.
    13  * file is included before the parent theme's file, so the child theme
    13  *
    14  * functions would be used.
    14  * @link https://codex.wordpress.org/Theme_Development
       
    15  * @link https://developer.wordpress.org/themes/advanced-topics/child-themes/
    15  *
    16  *
    16  * Functions that are not pluggable (not wrapped in function_exists()) are
    17  * Functions that are not pluggable (not wrapped in function_exists()) are
    17  * instead attached to a filter or action hook.
    18  * instead attached to a filter or action hook.
    18  *
    19  *
    19  * For more information on hooks, actions, and filters, @link https://codex.wordpress.org/Plugin_API
    20  * For more information on hooks, actions, and filters, @link https://codex.wordpress.org/Plugin_API
    74 	 * This theme styles the visual editor to resemble the theme style,
    75 	 * This theme styles the visual editor to resemble the theme style,
    75 	 * specifically font, colors, icons, and column width.
    76 	 * specifically font, colors, icons, and column width.
    76 	 */
    77 	 */
    77 	add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', twentythirteen_fonts_url() ) );
    78 	add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', twentythirteen_fonts_url() ) );
    78 
    79 
       
    80 	// Load regular editor styles into the new block-based editor.
       
    81 	add_theme_support( 'editor-styles' );
       
    82 
       
    83 	// Load default block styles.
       
    84 	add_theme_support( 'wp-block-styles' );
       
    85 
       
    86 	// Add support for full and wide align images.
       
    87 	add_theme_support( 'align-wide' );
       
    88 
       
    89 	// Add support for responsive embeds.
       
    90 	add_theme_support( 'responsive-embeds' );
       
    91 
       
    92 	// Add support for custom color scheme.
       
    93 	add_theme_support(
       
    94 		'editor-color-palette',
       
    95 		array(
       
    96 			array(
       
    97 				'name'  => __( 'Dark Gray', 'twentythirteen' ),
       
    98 				'slug'  => 'dark-gray',
       
    99 				'color' => '#141412',
       
   100 			),
       
   101 			array(
       
   102 				'name'  => __( 'Red', 'twentythirteen' ),
       
   103 				'slug'  => 'red',
       
   104 				'color' => '#bc360a',
       
   105 			),
       
   106 			array(
       
   107 				'name'  => __( 'Medium Orange', 'twentythirteen' ),
       
   108 				'slug'  => 'medium-orange',
       
   109 				'color' => '#db572f',
       
   110 			),
       
   111 			array(
       
   112 				'name'  => __( 'Light Orange', 'twentythirteen' ),
       
   113 				'slug'  => 'light-orange',
       
   114 				'color' => '#ea9629',
       
   115 			),
       
   116 			array(
       
   117 				'name'  => __( 'Yellow', 'twentythirteen' ),
       
   118 				'slug'  => 'yellow',
       
   119 				'color' => '#fbca3c',
       
   120 			),
       
   121 			array(
       
   122 				'name'  => __( 'White', 'twentythirteen' ),
       
   123 				'slug'  => 'white',
       
   124 				'color' => '#fff',
       
   125 			),
       
   126 			array(
       
   127 				'name'  => __( 'Dark Brown', 'twentythirteen' ),
       
   128 				'slug'  => 'dark-brown',
       
   129 				'color' => '#220e10',
       
   130 			),
       
   131 			array(
       
   132 				'name'  => __( 'Medium Brown', 'twentythirteen' ),
       
   133 				'slug'  => 'medium-brown',
       
   134 				'color' => '#722d19',
       
   135 			),
       
   136 			array(
       
   137 				'name'  => __( 'Light Brown', 'twentythirteen' ),
       
   138 				'slug'  => 'light-brown',
       
   139 				'color' => '#eadaa6',
       
   140 			),
       
   141 			array(
       
   142 				'name'  => __( 'Beige', 'twentythirteen' ),
       
   143 				'slug'  => 'beige',
       
   144 				'color' => '#e8e5ce',
       
   145 			),
       
   146 			array(
       
   147 				'name'  => __( 'Off-white', 'twentythirteen' ),
       
   148 				'slug'  => 'off-white',
       
   149 				'color' => '#f7f5e7',
       
   150 			),
       
   151 		)
       
   152 	);
       
   153 
    79 	// Adds RSS feed links to <head> for posts and comments.
   154 	// Adds RSS feed links to <head> for posts and comments.
    80 	add_theme_support( 'automatic-feed-links' );
   155 	add_theme_support( 'automatic-feed-links' );
    81 
   156 
    82 	/*
   157 	/*
    83 	 * Switches default core markup for search form, comment form,
   158 	 * Switches default core markup for search form, comment form,
    84 	 * and comments to output valid HTML5.
   159 	 * and comments to output valid HTML5.
    85 	 */
   160 	 */
    86 	add_theme_support(
   161 	add_theme_support(
    87 		'html5', array(
   162 		'html5',
       
   163 		array(
    88 			'search-form',
   164 			'search-form',
    89 			'comment-form',
   165 			'comment-form',
    90 			'comment-list',
   166 			'comment-list',
    91 			'gallery',
   167 			'gallery',
    92 			'caption',
   168 			'caption',
    96 	/*
   172 	/*
    97 	 * This theme supports all available post formats by default.
   173 	 * This theme supports all available post formats by default.
    98 	 * See https://codex.wordpress.org/Post_Formats
   174 	 * See https://codex.wordpress.org/Post_Formats
    99 	 */
   175 	 */
   100 	add_theme_support(
   176 	add_theme_support(
   101 		'post-formats', array(
   177 		'post-formats',
       
   178 		array(
   102 			'aside',
   179 			'aside',
   103 			'audio',
   180 			'audio',
   104 			'chat',
   181 			'chat',
   105 			'gallery',
   182 			'gallery',
   106 			'image',
   183 			'image',
   199 
   276 
   200 	// Add Source Sans Pro and Bitter fonts, used in the main stylesheet.
   277 	// Add Source Sans Pro and Bitter fonts, used in the main stylesheet.
   201 	wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null );
   278 	wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null );
   202 
   279 
   203 	// Add Genericons font, used in the main stylesheet.
   280 	// Add Genericons font, used in the main stylesheet.
   204 	wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.03' );
   281 	wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.0.3' );
   205 
   282 
   206 	// Loads our main stylesheet.
   283 	// Loads our main stylesheet.
   207 	wp_enqueue_style( 'twentythirteen-style', get_stylesheet_uri(), array(), '2013-07-18' );
   284 	wp_enqueue_style( 'twentythirteen-style', get_stylesheet_uri(), array(), '2013-07-18' );
       
   285 
       
   286 	// Theme block stylesheet.
       
   287 	wp_enqueue_style( 'twentythirteen-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'twentythirteen-style' ), '2018-12-30' );
   208 
   288 
   209 	// Loads the Internet Explorer specific stylesheet.
   289 	// Loads the Internet Explorer specific stylesheet.
   210 	wp_enqueue_style( 'twentythirteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentythirteen-style' ), '2013-07-18' );
   290 	wp_enqueue_style( 'twentythirteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentythirteen-style' ), '2013-07-18' );
   211 	wp_style_add_data( 'twentythirteen-ie', 'conditional', 'lt IE 9' );
   291 	wp_style_add_data( 'twentythirteen-ie', 'conditional', 'lt IE 9' );
   212 }
   292 }
   234 	}
   314 	}
   235 
   315 
   236 	return $urls;
   316 	return $urls;
   237 }
   317 }
   238 add_filter( 'wp_resource_hints', 'twentythirteen_resource_hints', 10, 2 );
   318 add_filter( 'wp_resource_hints', 'twentythirteen_resource_hints', 10, 2 );
       
   319 
       
   320 /**
       
   321  * Enqueue styles for the block-based editor.
       
   322  *
       
   323  * @since Twenty Thirteen 2.5
       
   324  */
       
   325 function twentythirteen_block_editor_styles() {
       
   326 	// Block styles.
       
   327 	wp_enqueue_style( 'twentythirteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '2018-12-30' );
       
   328 	// Add custom fonts.
       
   329 	wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null );
       
   330 }
       
   331 add_action( 'enqueue_block_editor_assets', 'twentythirteen_block_editor_styles' );
   239 
   332 
   240 /**
   333 /**
   241  * Filter the page title.
   334  * Filter the page title.
   242  *
   335  *
   243  * Creates a nicely formatted and more specific title element text for output
   336  * Creates a nicely formatted and more specific title element text for output
   332 			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentythirteen' ) ); ?></div>
   425 			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentythirteen' ) ); ?></div>
   333 			<?php endif; ?>
   426 			<?php endif; ?>
   334 
   427 
   335 		</div><!-- .nav-links -->
   428 		</div><!-- .nav-links -->
   336 	</nav><!-- .navigation -->
   429 	</nav><!-- .navigation -->
   337 	<?php
   430 		<?php
   338 	}
   431 	}
   339 endif;
   432 endif;
   340 
   433 
   341 if ( ! function_exists( 'twentythirteen_post_nav' ) ) :
   434 if ( ! function_exists( 'twentythirteen_post_nav' ) ) :
   342 	/**
   435 	/**
   362 			<?php previous_post_link( '%link', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'twentythirteen' ) ); ?>
   455 			<?php previous_post_link( '%link', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'twentythirteen' ) ); ?>
   363 			<?php next_post_link( '%link', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'twentythirteen' ) ); ?>
   456 			<?php next_post_link( '%link', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'twentythirteen' ) ); ?>
   364 
   457 
   365 		</div><!-- .nav-links -->
   458 		</div><!-- .nav-links -->
   366 	</nav><!-- .navigation -->
   459 	</nav><!-- .navigation -->
   367 	<?php
   460 		<?php
   368 	}
   461 	}
   369 endif;
   462 endif;
   370 
   463 
   371 if ( ! function_exists( 'twentythirteen_entry_meta' ) ) :
   464 if ( ! function_exists( 'twentythirteen_entry_meta' ) ) :
   372 	/**
   465 	/**
   493 			}
   586 			}
   494 
   587 
   495 			// get the URL of the next image attachment...
   588 			// get the URL of the next image attachment...
   496 			if ( $next_id ) {
   589 			if ( $next_id ) {
   497 				$next_attachment_url = get_attachment_link( $next_id );
   590 				$next_attachment_url = get_attachment_link( $next_id );
   498 			} // or get the URL of the first image attachment.
   591 			} else {
   499 			else {
   592 				// or get the URL of the first image attachment.
   500 				$next_attachment_url = get_attachment_link( reset( $attachment_ids ) );
   593 				$next_attachment_url = get_attachment_link( reset( $attachment_ids ) );
   501 			}
   594 			}
   502 		}
   595 		}
   503 
   596 
   504 		printf(
   597 		printf(
   609 	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
   702 	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
   610 	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
   703 	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
   611 
   704 
   612 	if ( isset( $wp_customize->selective_refresh ) ) {
   705 	if ( isset( $wp_customize->selective_refresh ) ) {
   613 		$wp_customize->selective_refresh->add_partial(
   706 		$wp_customize->selective_refresh->add_partial(
   614 			'blogname', array(
   707 			'blogname',
       
   708 			array(
   615 				'selector'            => '.site-title',
   709 				'selector'            => '.site-title',
   616 				'container_inclusive' => false,
   710 				'container_inclusive' => false,
   617 				'render_callback'     => 'twentythirteen_customize_partial_blogname',
   711 				'render_callback'     => 'twentythirteen_customize_partial_blogname',
   618 			)
   712 			)
   619 		);
   713 		);
   620 		$wp_customize->selective_refresh->add_partial(
   714 		$wp_customize->selective_refresh->add_partial(
   621 			'blogdescription', array(
   715 			'blogdescription',
       
   716 			array(
   622 				'selector'            => '.site-description',
   717 				'selector'            => '.site-description',
   623 				'container_inclusive' => false,
   718 				'container_inclusive' => false,
   624 				'render_callback'     => 'twentythirteen_customize_partial_blogdescription',
   719 				'render_callback'     => 'twentythirteen_customize_partial_blogdescription',
   625 			)
   720 			)
   626 		);
   721 		);
   681 	$args['format']   = 'list';
   776 	$args['format']   = 'list';
   682 
   777 
   683 	return $args;
   778 	return $args;
   684 }
   779 }
   685 add_filter( 'widget_tag_cloud_args', 'twentythirteen_widget_tag_cloud_args' );
   780 add_filter( 'widget_tag_cloud_args', 'twentythirteen_widget_tag_cloud_args' );
       
   781 
       
   782 if ( ! function_exists( 'wp_body_open' ) ) :
       
   783 	/**
       
   784 	 * Fire the wp_body_open action.
       
   785 	 *
       
   786 	 * Added for backwards compatibility to support pre 5.2.0 WordPress versions.
       
   787 	 *
       
   788 	 * @since Twenty Thirteen 2.8
       
   789 	 */
       
   790 	function wp_body_open() {
       
   791 		/**
       
   792 		 * Triggered after the opening <body> tag.
       
   793 		 *
       
   794 		 * @since Twenty Thirteen 2.8
       
   795 		 */
       
   796 		do_action( 'wp_body_open' );
       
   797 	}
       
   798 endif;