[ Index ]

PHP Cross Reference of WordPress

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          // Add support for custom line height.
 180          add_theme_support( 'custom-line-height' );
 181      }
 182  endif;
 183  add_action( 'after_setup_theme', 'twentynineteen_setup' );
 184  
 185  /**
 186   * Register widget area.
 187   *
 188   * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 189   */
 190  function twentynineteen_widgets_init() {
 191  
 192      register_sidebar(
 193          array(
 194              'name'          => __( 'Footer', 'twentynineteen' ),
 195              'id'            => 'sidebar-1',
 196              'description'   => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ),
 197              'before_widget' => '<section id="%1$s" class="widget %2$s">',
 198              'after_widget'  => '</section>',
 199              'before_title'  => '<h2 class="widget-title">',
 200              'after_title'   => '</h2>',
 201          )
 202      );
 203  
 204  }
 205  add_action( 'widgets_init', 'twentynineteen_widgets_init' );
 206  
 207  /**
 208   * Set the content width in pixels, based on the theme's design and stylesheet.
 209   *
 210   * Priority 0 to make it available to lower priority callbacks.
 211   *
 212   * @global int $content_width Content width.
 213   */
 214  function twentynineteen_content_width() {
 215      // This variable is intended to be overruled from themes.
 216      // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
 217      // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
 218      $GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 );
 219  }
 220  add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 );
 221  
 222  /**
 223   * Enqueue scripts and styles.
 224   */
 225  function twentynineteen_scripts() {
 226      wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
 227  
 228      wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );
 229  
 230      if ( has_nav_menu( 'menu-1' ) ) {
 231          wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '20181214', true );
 232          wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '20181231', true );
 233      }
 234  
 235      wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
 236  
 237      if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
 238          wp_enqueue_script( 'comment-reply' );
 239      }
 240  }
 241  add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );
 242  
 243  /**
 244   * Fix skip link focus in IE11.
 245   *
 246   * This does not enqueue the script because it is tiny and because it is only for IE11,
 247   * thus it does not warrant having an entire dedicated blocking script being loaded.
 248   *
 249   * @link https://git.io/vWdr2
 250   */
 251  function twentynineteen_skip_link_focus_fix() {
 252      // The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
 253      ?>
 254      <script>
 255      /(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);
 256      </script>
 257      <?php
 258  }
 259  add_action( 'wp_print_footer_scripts', 'twentynineteen_skip_link_focus_fix' );
 260  
 261  /**
 262   * Enqueue supplemental block editor styles.
 263   */
 264  function twentynineteen_editor_customizer_styles() {
 265  
 266      wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.1', 'all' );
 267  
 268      if ( 'custom' === get_theme_mod( 'primary_color' ) ) {
 269          // Include color patterns.
 270          require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
 271          wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() );
 272      }
 273  }
 274  add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' );
 275  
 276  /**
 277   * Display custom color CSS in customizer and on frontend.
 278   */
 279  function twentynineteen_colors_css_wrap() {
 280  
 281      // Only include custom colors in customizer or frontend.
 282      if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'primary_color', 'default' ) ) || is_admin() ) {
 283          return;
 284      }
 285  
 286      require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
 287  
 288      $primary_color = 199;
 289      if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
 290          $primary_color = get_theme_mod( 'primary_color_hue', 199 );
 291      }
 292      ?>
 293  
 294      <style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
 295          <?php echo twentynineteen_custom_colors_css(); ?>
 296      </style>
 297      <?php
 298  }
 299  add_action( 'wp_head', 'twentynineteen_colors_css_wrap' );
 300  
 301  /**
 302   * SVG Icons class.
 303   */
 304  require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php';
 305  
 306  /**
 307   * Custom Comment Walker template.
 308   */
 309  require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php';
 310  
 311  /**
 312   * Common theme functions.
 313   */
 314  require get_template_directory() . '/inc/helper-functions.php';
 315  
 316  /**
 317   * SVG Icons related functions.
 318   */
 319  require get_template_directory() . '/inc/icon-functions.php';
 320  
 321  /**
 322   * Enhance the theme by hooking into WordPress.
 323   */
 324  require get_template_directory() . '/inc/template-functions.php';
 325  
 326  /**
 327   * Custom template tags for the theme.
 328   */
 329  require get_template_directory() . '/inc/template-tags.php';
 330  
 331  /**
 332   * Customizer additions.
 333   */
 334  require get_template_directory() . '/inc/customizer.php';
 335  
 336  /**
 337   * Block Patterns.
 338   */
 339  require get_template_directory() . '/inc/block-patterns.php';


Generated: Fri Nov 27 01:00:04 2020 Cross-referenced by PHPXref 0.7.1