[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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 Twenty Nineteen 1.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                  'navigation-widgets',
  80              )
  81          );
  82  
  83          /**
  84           * Add support for core custom logo.
  85           *
  86           * @link https://codex.wordpress.org/Theme_Logo
  87           */
  88          add_theme_support(
  89              'custom-logo',
  90              array(
  91                  'height'      => 190,
  92                  'width'       => 190,
  93                  'flex-width'  => false,
  94                  'flex-height' => false,
  95              )
  96          );
  97  
  98          // Add theme support for selective refresh for widgets.
  99          add_theme_support( 'customize-selective-refresh-widgets' );
 100  
 101          // Add support for Block Styles.
 102          add_theme_support( 'wp-block-styles' );
 103  
 104          // Add support for full and wide align images.
 105          add_theme_support( 'align-wide' );
 106  
 107          // Add support for editor styles.
 108          add_theme_support( 'editor-styles' );
 109  
 110          // Enqueue editor styles.
 111          add_editor_style( 'style-editor.css' );
 112  
 113          // Add custom editor font sizes.
 114          add_theme_support(
 115              'editor-font-sizes',
 116              array(
 117                  array(
 118                      'name'      => __( 'Small', 'twentynineteen' ),
 119                      'shortName' => __( 'S', 'twentynineteen' ),
 120                      'size'      => 19.5,
 121                      'slug'      => 'small',
 122                  ),
 123                  array(
 124                      'name'      => __( 'Normal', 'twentynineteen' ),
 125                      'shortName' => __( 'M', 'twentynineteen' ),
 126                      'size'      => 22,
 127                      'slug'      => 'normal',
 128                  ),
 129                  array(
 130                      'name'      => __( 'Large', 'twentynineteen' ),
 131                      'shortName' => __( 'L', 'twentynineteen' ),
 132                      'size'      => 36.5,
 133                      'slug'      => 'large',
 134                  ),
 135                  array(
 136                      'name'      => __( 'Huge', 'twentynineteen' ),
 137                      'shortName' => __( 'XL', 'twentynineteen' ),
 138                      'size'      => 49.5,
 139                      'slug'      => 'huge',
 140                  ),
 141              )
 142          );
 143  
 144          // Editor color palette.
 145          add_theme_support(
 146              'editor-color-palette',
 147              array(
 148                  array(
 149                      'name'  => 'default' === get_theme_mod( 'primary_color' ) ? __( 'Blue', 'twentynineteen' ) : null,
 150                      'slug'  => 'primary',
 151                      'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 33 ),
 152                  ),
 153                  array(
 154                      'name'  => 'default' === get_theme_mod( 'primary_color' ) ? __( 'Dark Blue', 'twentynineteen' ) : null,
 155                      'slug'  => 'secondary',
 156                      'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 23 ),
 157                  ),
 158                  array(
 159                      'name'  => __( 'Dark Gray', 'twentynineteen' ),
 160                      'slug'  => 'dark-gray',
 161                      'color' => '#111',
 162                  ),
 163                  array(
 164                      'name'  => __( 'Light Gray', 'twentynineteen' ),
 165                      'slug'  => 'light-gray',
 166                      'color' => '#767676',
 167                  ),
 168                  array(
 169                      'name'  => __( 'White', 'twentynineteen' ),
 170                      'slug'  => 'white',
 171                      'color' => '#FFF',
 172                  ),
 173              )
 174          );
 175  
 176          // Add support for responsive embedded content.
 177          add_theme_support( 'responsive-embeds' );
 178      }
 179  endif;
 180  add_action( 'after_setup_theme', 'twentynineteen_setup' );
 181  
 182  /**
 183   * Register widget area.
 184   *
 185   * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 186   */
 187  function twentynineteen_widgets_init() {
 188  
 189      register_sidebar(
 190          array(
 191              'name'          => __( 'Footer', 'twentynineteen' ),
 192              'id'            => 'sidebar-1',
 193              'description'   => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ),
 194              'before_widget' => '<section id="%1$s" class="widget %2$s">',
 195              'after_widget'  => '</section>',
 196              'before_title'  => '<h2 class="widget-title">',
 197              'after_title'   => '</h2>',
 198          )
 199      );
 200  
 201  }
 202  add_action( 'widgets_init', 'twentynineteen_widgets_init' );
 203  
 204  /**
 205   * Set the content width in pixels, based on the theme's design and stylesheet.
 206   *
 207   * Priority 0 to make it available to lower priority callbacks.
 208   *
 209   * @global int $content_width Content width.
 210   */
 211  function twentynineteen_content_width() {
 212      // This variable is intended to be overruled from themes.
 213      // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
 214      // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
 215      $GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 );
 216  }
 217  add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 );
 218  
 219  /**
 220   * Enqueue scripts and styles.
 221   */
 222  function twentynineteen_scripts() {
 223      wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
 224  
 225      wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );
 226  
 227      if ( has_nav_menu( 'menu-1' ) ) {
 228          wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '20181214', true );
 229          wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '20181231', true );
 230      }
 231  
 232      wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
 233  
 234      if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
 235          wp_enqueue_script( 'comment-reply' );
 236      }
 237  }
 238  add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );
 239  
 240  /**
 241   * Fix skip link focus in IE11.
 242   *
 243   * This does not enqueue the script because it is tiny and because it is only for IE11,
 244   * thus it does not warrant having an entire dedicated blocking script being loaded.
 245   *
 246   * @link https://git.io/vWdr2
 247   */
 248  function twentynineteen_skip_link_focus_fix() {
 249      // The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
 250      ?>
 251      <script>
 252      /(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);
 253      </script>
 254      <?php
 255  }
 256  add_action( 'wp_print_footer_scripts', 'twentynineteen_skip_link_focus_fix' );
 257  
 258  /**
 259   * Enqueue supplemental block editor styles.
 260   */
 261  function twentynineteen_editor_customizer_styles() {
 262  
 263      wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.1', 'all' );
 264  
 265      if ( 'custom' === get_theme_mod( 'primary_color' ) ) {
 266          // Include color patterns.
 267          require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
 268          wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() );
 269      }
 270  }
 271  add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' );
 272  
 273  /**
 274   * Display custom color CSS in customizer and on frontend.
 275   */
 276  function twentynineteen_colors_css_wrap() {
 277  
 278      // Only include custom colors in customizer or frontend.
 279      if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'primary_color', 'default' ) ) || is_admin() ) {
 280          return;
 281      }
 282  
 283      require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
 284  
 285      $primary_color = 199;
 286      if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
 287          $primary_color = get_theme_mod( 'primary_color_hue', 199 );
 288      }
 289      ?>
 290  
 291      <style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
 292          <?php echo twentynineteen_custom_colors_css(); ?>
 293      </style>
 294      <?php
 295  }
 296  add_action( 'wp_head', 'twentynineteen_colors_css_wrap' );
 297  
 298  /**
 299   * SVG Icons class.
 300   */
 301  require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php';
 302  
 303  /**
 304   * Custom Comment Walker template.
 305   */
 306  require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php';
 307  
 308  /**
 309   * Common theme functions.
 310   */
 311  require get_template_directory() . '/inc/helper-functions.php';
 312  
 313  /**
 314   * SVG Icons related functions.
 315   */
 316  require get_template_directory() . '/inc/icon-functions.php';
 317  
 318  /**
 319   * Enhance the theme by hooking into WordPress.
 320   */
 321  require get_template_directory() . '/inc/template-functions.php';
 322  
 323  /**
 324   * Custom template tags for the theme.
 325   */
 326  require get_template_directory() . '/inc/template-tags.php';
 327  
 328  /**
 329   * Customizer additions.
 330   */
 331  require get_template_directory() . '/inc/customizer.php';


Generated : Thu Oct 22 08:20:02 2020 Cross-referenced by PHPXref