[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-content/themes/twentynineteen/ -> functions.php (source)

   1  <?php
   2  /**
   3   * Twenty Nineteen functions and definitions
   4   *
   5   * @link https://developer.wordpress.org/themes/basics/theme-functions/
   6   *
   7   * @package WordPress
   8   * @subpackage Twenty_Nineteen
   9   * @since 1.0.0
  10   */
  11  
  12  /**
  13   * Twenty Nineteen only works in WordPress 4.7 or later.
  14   */
  15  if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
  16      require get_template_directory() . '/inc/back-compat.php';
  17      return;
  18  }
  19  
  20  if ( ! function_exists( 'twentynineteen_setup' ) ) :
  21      /**
  22       * Sets up theme defaults and registers support for various WordPress features.
  23       *
  24       * Note that this function is hooked into the after_setup_theme hook, which
  25       * runs before the init hook. The init hook is too late for some features, such
  26       * as indicating support for post thumbnails.
  27       */
  28  	function twentynineteen_setup() {
  29          /*
  30           * Make theme available for translation.
  31           * Translations can be filed in the /languages/ directory.
  32           * If you're building a theme based on Twenty Nineteen, use a find and replace
  33           * to change 'twentynineteen' to the name of your theme in all the template files.
  34           */
  35          load_theme_textdomain( 'twentynineteen', get_template_directory() . '/languages' );
  36  
  37          // Add default posts and comments RSS feed links to head.
  38          add_theme_support( 'automatic-feed-links' );
  39  
  40          /*
  41           * Let WordPress manage the document title.
  42           * By adding theme support, we declare that this theme does not use a
  43           * hard-coded <title> tag in the document head, and expect WordPress to
  44           * provide it for us.
  45           */
  46          add_theme_support( 'title-tag' );
  47  
  48          /*
  49           * Enable support for Post Thumbnails on posts and pages.
  50           *
  51           * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  52           */
  53          add_theme_support( 'post-thumbnails' );
  54          set_post_thumbnail_size( 1568, 9999 );
  55  
  56          // This theme uses wp_nav_menu() in two locations.
  57          register_nav_menus(
  58              array(
  59                  'menu-1' => __( 'Primary', 'twentynineteen' ),
  60                  'footer' => __( 'Footer Menu', 'twentynineteen' ),
  61                  'social' => __( 'Social Links Menu', 'twentynineteen' ),
  62              )
  63          );
  64  
  65          /*
  66           * Switch default core markup for search form, comment form, and comments
  67           * to output valid HTML5.
  68           */
  69          add_theme_support(
  70              'html5',
  71              array(
  72                  'search-form',
  73                  'comment-form',
  74                  'comment-list',
  75                  'gallery',
  76                  'caption',
  77                  'script',
  78                  'style',
  79              )
  80          );
  81  
  82          /**
  83           * Add support for core custom logo.
  84           *
  85           * @link https://codex.wordpress.org/Theme_Logo
  86           */
  87          add_theme_support(
  88              'custom-logo',
  89              array(
  90                  'height'      => 190,
  91                  'width'       => 190,
  92                  'flex-width'  => false,
  93                  'flex-height' => false,
  94              )
  95          );
  96  
  97          // Add theme support for selective refresh for widgets.
  98          add_theme_support( 'customize-selective-refresh-widgets' );
  99  
 100          // Add support for Block Styles.
 101          add_theme_support( 'wp-block-styles' );
 102  
 103          // Add support for full and wide align images.
 104          add_theme_support( 'align-wide' );
 105  
 106          // Add support for editor styles.
 107          add_theme_support( 'editor-styles' );
 108  
 109          // Enqueue editor styles.
 110          add_editor_style( 'style-editor.css' );
 111  
 112          // Add custom editor font sizes.
 113          add_theme_support(
 114              'editor-font-sizes',
 115              array(
 116                  array(
 117                      'name'      => __( 'Small', 'twentynineteen' ),
 118                      'shortName' => __( 'S', 'twentynineteen' ),
 119                      'size'      => 19.5,
 120                      'slug'      => 'small',
 121                  ),
 122                  array(
 123                      'name'      => __( 'Normal', 'twentynineteen' ),
 124                      'shortName' => __( 'M', 'twentynineteen' ),
 125                      'size'      => 22,
 126                      'slug'      => 'normal',
 127                  ),
 128                  array(
 129                      'name'      => __( 'Large', 'twentynineteen' ),
 130                      'shortName' => __( 'L', 'twentynineteen' ),
 131                      'size'      => 36.5,
 132                      'slug'      => 'large',
 133                  ),
 134                  array(
 135                      'name'      => __( 'Huge', 'twentynineteen' ),
 136                      'shortName' => __( 'XL', 'twentynineteen' ),
 137                      'size'      => 49.5,
 138                      'slug'      => 'huge',
 139                  ),
 140              )
 141          );
 142  
 143          // Editor color palette.
 144          add_theme_support(
 145              'editor-color-palette',
 146              array(
 147                  array(
 148                      'name'  => 'default' === get_theme_mod( 'primary_color' ) ? __( 'Blue', 'twentynineteen' ) : null,
 149                      'slug'  => 'primary',
 150                      'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 33 ),
 151                  ),
 152                  array(
 153                      'name'  => 'default' === get_theme_mod( 'primary_color' ) ? __( 'Dark Blue', 'twentynineteen' ) : null,
 154                      'slug'  => 'secondary',
 155                      'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 23 ),
 156                  ),
 157                  array(
 158                      'name'  => __( 'Dark Gray', 'twentynineteen' ),
 159                      'slug'  => 'dark-gray',
 160                      'color' => '#111',
 161                  ),
 162                  array(
 163                      'name'  => __( 'Light Gray', 'twentynineteen' ),
 164                      'slug'  => 'light-gray',
 165                      'color' => '#767676',
 166                  ),
 167                  array(
 168                      'name'  => __( 'White', 'twentynineteen' ),
 169                      'slug'  => 'white',
 170                      'color' => '#FFF',
 171                  ),
 172              )
 173          );
 174  
 175          // Add support for responsive embedded content.
 176          add_theme_support( 'responsive-embeds' );
 177      }
 178  endif;
 179  add_action( 'after_setup_theme', 'twentynineteen_setup' );
 180  
 181  /**
 182   * Register widget area.
 183   *
 184   * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 185   */
 186  function twentynineteen_widgets_init() {
 187  
 188      register_sidebar(
 189          array(
 190              'name'          => __( 'Footer', 'twentynineteen' ),
 191              'id'            => 'sidebar-1',
 192              'description'   => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ),
 193              'before_widget' => '<section id="%1$s" class="widget %2$s">',
 194              'after_widget'  => '</section>',
 195              'before_title'  => '<h2 class="widget-title">',
 196              'after_title'   => '</h2>',
 197          )
 198      );
 199  
 200  }
 201  add_action( 'widgets_init', 'twentynineteen_widgets_init' );
 202  
 203  /**
 204   * Set the content width in pixels, based on the theme's design and stylesheet.
 205   *
 206   * Priority 0 to make it available to lower priority callbacks.
 207   *
 208   * @global int $content_width Content width.
 209   */
 210  function twentynineteen_content_width() {
 211      // This variable is intended to be overruled from themes.
 212      // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
 213      // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
 214      $GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 );
 215  }
 216  add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 );
 217  
 218  /**
 219   * Enqueue scripts and styles.
 220   */
 221  function twentynineteen_scripts() {
 222      wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
 223  
 224      wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );
 225  
 226      if ( has_nav_menu( 'menu-1' ) ) {
 227          wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '20181214', true );
 228          wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '20181231', true );
 229      }
 230  
 231      wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
 232  
 233      if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
 234          wp_enqueue_script( 'comment-reply' );
 235      }
 236  }
 237  add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );
 238  
 239  /**
 240   * Fix skip link focus in IE11.
 241   *
 242   * This does not enqueue the script because it is tiny and because it is only for IE11,
 243   * thus it does not warrant having an entire dedicated blocking script being loaded.
 244   *
 245   * @link https://git.io/vWdr2
 246   */
 247  function twentynineteen_skip_link_focus_fix() {
 248      // The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
 249      ?>
 250      <script>
 251      /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
 252      </script>
 253      <?php
 254  }
 255  add_action( 'wp_print_footer_scripts', 'twentynineteen_skip_link_focus_fix' );
 256  
 257  /**
 258   * Enqueue supplemental block editor styles.
 259   */
 260  function twentynineteen_editor_customizer_styles() {
 261  
 262      wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.1', 'all' );
 263  
 264      if ( 'custom' === get_theme_mod( 'primary_color' ) ) {
 265          // Include color patterns.
 266          require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
 267          wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() );
 268      }
 269  }
 270  add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' );
 271  
 272  /**
 273   * Display custom color CSS in customizer and on frontend.
 274   */
 275  function twentynineteen_colors_css_wrap() {
 276  
 277      // Only include custom colors in customizer or frontend.
 278      if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'primary_color', 'default' ) ) || is_admin() ) {
 279          return;
 280      }
 281  
 282      require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
 283  
 284      $primary_color = 199;
 285      if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
 286          $primary_color = get_theme_mod( 'primary_color_hue', 199 );
 287      }
 288      ?>
 289  
 290      <style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
 291          <?php echo twentynineteen_custom_colors_css(); ?>
 292      </style>
 293      <?php
 294  }
 295  add_action( 'wp_head', 'twentynineteen_colors_css_wrap' );
 296  
 297  /**
 298   * SVG Icons class.
 299   */
 300  require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php';
 301  
 302  /**
 303   * Custom Comment Walker template.
 304   */
 305  require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php';
 306  
 307  /**
 308   * Enhance the theme by hooking into WordPress.
 309   */
 310  require get_template_directory() . '/inc/template-functions.php';
 311  
 312  /**
 313   * SVG Icons related functions.
 314   */
 315  require get_template_directory() . '/inc/icon-functions.php';
 316  
 317  /**
 318   * Custom template tags for the theme.
 319   */
 320  require get_template_directory() . '/inc/template-tags.php';
 321  
 322  /**
 323   * Customizer additions.
 324   */
 325  require get_template_directory() . '/inc/customizer.php';


Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7