[ 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  if ( ! function_exists( 'wp_get_list_item_separator' ) ) :
 186      /**
 187       * Retrieves the list item separator based on the locale.
 188       *
 189       * Added for backward compatibility to support pre-6.0.0 WordPress versions.
 190       *
 191       * @since 6.0.0
 192       */
 193  	function wp_get_list_item_separator() {
 194          /* translators: Used between list items, there is a space after the comma. */
 195          return __( ', ', 'twentynineteen' );
 196      }
 197  endif;
 198  
 199  /**
 200   * Register widget area.
 201   *
 202   * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 203   */
 204  function twentynineteen_widgets_init() {
 205  
 206      register_sidebar(
 207          array(
 208              'name'          => __( 'Footer', 'twentynineteen' ),
 209              'id'            => 'sidebar-1',
 210              'description'   => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ),
 211              'before_widget' => '<section id="%1$s" class="widget %2$s">',
 212              'after_widget'  => '</section>',
 213              'before_title'  => '<h2 class="widget-title">',
 214              'after_title'   => '</h2>',
 215          )
 216      );
 217  
 218  }
 219  add_action( 'widgets_init', 'twentynineteen_widgets_init' );
 220  
 221  /**
 222   * Replaces "[...]" (appended to automatically generated excerpts) with ... and
 223   * a 'Continue reading' link.
 224   *
 225   * @since Twenty Nineteen 2.0
 226   *
 227   * @param string $link Link to single post/page.
 228   * @return string 'Continue reading' link prepended with an ellipsis.
 229   */
 230  function twentynineteen_excerpt_more( $link ) {
 231      if ( is_admin() ) {
 232          return $link;
 233      }
 234  
 235      $link = sprintf(
 236          '<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>',
 237          esc_url( get_permalink( get_the_ID() ) ),
 238          /* translators: %s: Post title. Only visible to screen readers. */
 239          sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentynineteen' ), get_the_title( get_the_ID() ) )
 240      );
 241      return ' &hellip; ' . $link;
 242  }
 243  add_filter( 'excerpt_more', 'twentynineteen_excerpt_more' );
 244  
 245  /**
 246   * Set the content width in pixels, based on the theme's design and stylesheet.
 247   *
 248   * Priority 0 to make it available to lower priority callbacks.
 249   *
 250   * @global int $content_width Content width.
 251   */
 252  function twentynineteen_content_width() {
 253      // This variable is intended to be overruled from themes.
 254      // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
 255      // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
 256      $GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 );
 257  }
 258  add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 );
 259  
 260  /**
 261   * Enqueue scripts and styles.
 262   */
 263  function twentynineteen_scripts() {
 264      wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
 265  
 266      wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );
 267  
 268      if ( has_nav_menu( 'menu-1' ) ) {
 269          wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '20181214', true );
 270          wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '20181231', true );
 271      }
 272  
 273      wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
 274  
 275      if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
 276          wp_enqueue_script( 'comment-reply' );
 277      }
 278  }
 279  add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );
 280  
 281  /**
 282   * Fix skip link focus in IE11.
 283   *
 284   * This does not enqueue the script because it is tiny and because it is only for IE11,
 285   * thus it does not warrant having an entire dedicated blocking script being loaded.
 286   *
 287   * @link https://git.io/vWdr2
 288   */
 289  function twentynineteen_skip_link_focus_fix() {
 290      // The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
 291      ?>
 292      <script>
 293      /(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);
 294      </script>
 295      <?php
 296  }
 297  add_action( 'wp_print_footer_scripts', 'twentynineteen_skip_link_focus_fix' );
 298  
 299  /**
 300   * Enqueue supplemental block editor styles.
 301   */
 302  function twentynineteen_editor_customizer_styles() {
 303  
 304      wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.1', 'all' );
 305  
 306      if ( 'custom' === get_theme_mod( 'primary_color' ) ) {
 307          // Include color patterns.
 308          require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
 309          wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() );
 310      }
 311  }
 312  add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' );
 313  
 314  /**
 315   * Display custom color CSS in customizer and on frontend.
 316   */
 317  function twentynineteen_colors_css_wrap() {
 318  
 319      // Only include custom colors in customizer or frontend.
 320      if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'primary_color', 'default' ) ) || is_admin() ) {
 321          return;
 322      }
 323  
 324      require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
 325  
 326      $primary_color = 199;
 327      if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) {
 328          $primary_color = get_theme_mod( 'primary_color_hue', 199 );
 329      }
 330      ?>
 331  
 332      <style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>>
 333          <?php echo twentynineteen_custom_colors_css(); ?>
 334      </style>
 335      <?php
 336  }
 337  add_action( 'wp_head', 'twentynineteen_colors_css_wrap' );
 338  
 339  /**
 340   * SVG Icons class.
 341   */
 342  require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php';
 343  
 344  /**
 345   * Custom Comment Walker template.
 346   */
 347  require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php';
 348  
 349  /**
 350   * Common theme functions.
 351   */
 352  require get_template_directory() . '/inc/helper-functions.php';
 353  
 354  /**
 355   * SVG Icons related functions.
 356   */
 357  require get_template_directory() . '/inc/icon-functions.php';
 358  
 359  /**
 360   * Enhance the theme by hooking into WordPress.
 361   */
 362  require get_template_directory() . '/inc/template-functions.php';
 363  
 364  /**
 365   * Custom template tags for the theme.
 366   */
 367  require get_template_directory() . '/inc/template-tags.php';
 368  
 369  /**
 370   * Customizer additions.
 371   */
 372  require get_template_directory() . '/inc/customizer.php';
 373  
 374  /**
 375   * Block Patterns.
 376   */
 377  require get_template_directory() . '/inc/block-patterns.php';


Generated: Sun Dec 22 01:00:02 2024 Cross-referenced by PHPXref 0.7.1