| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 * @global string $wp_version The WordPress version string. 16 */ 17 if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) { 18 require get_template_directory() . '/inc/back-compat.php'; 19 return; 20 } 21 22 if ( ! function_exists( 'twentynineteen_setup' ) ) : 23 /** 24 * Sets up theme defaults and registers support for various WordPress features. 25 * 26 * Note that this function is hooked into the after_setup_theme hook, which 27 * runs before the init hook. The init hook is too late for some features, such 28 * as indicating support for post thumbnails. 29 */ 30 function twentynineteen_setup() { 31 32 // Add default posts and comments RSS feed links to head. 33 add_theme_support( 'automatic-feed-links' ); 34 35 /* 36 * Let WordPress manage the document title. 37 * By adding theme support, we declare that this theme does not use a 38 * hard-coded <title> tag in the document head, and expect WordPress to 39 * provide it for us. 40 */ 41 add_theme_support( 'title-tag' ); 42 43 /* 44 * Enable support for Post Thumbnails on posts and pages. 45 * 46 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ 47 */ 48 add_theme_support( 'post-thumbnails' ); 49 set_post_thumbnail_size( 1568, 9999 ); 50 51 // This theme uses wp_nav_menu() in two locations. 52 register_nav_menus( 53 array( 54 'menu-1' => __( 'Primary', 'twentynineteen' ), 55 'footer' => __( 'Footer Menu', 'twentynineteen' ), 56 'social' => __( 'Social Links Menu', 'twentynineteen' ), 57 ) 58 ); 59 60 /* 61 * Switch default core markup for search form, comment form, and comments 62 * to output valid HTML5. 63 */ 64 add_theme_support( 65 'html5', 66 array( 67 'search-form', 68 'comment-form', 69 'comment-list', 70 'gallery', 71 'caption', 72 'script', 73 'style', 74 'navigation-widgets', 75 ) 76 ); 77 78 /** 79 * Add support for core custom logo. 80 * 81 * @link https://codex.wordpress.org/Theme_Logo 82 */ 83 add_theme_support( 84 'custom-logo', 85 array( 86 'height' => 190, 87 'width' => 190, 88 'flex-width' => false, 89 'flex-height' => false, 90 ) 91 ); 92 93 // Add theme support for selective refresh for widgets. 94 add_theme_support( 'customize-selective-refresh-widgets' ); 95 96 // Add support for Block Styles. 97 add_theme_support( 'wp-block-styles' ); 98 99 // Add support for full and wide align images. 100 add_theme_support( 'align-wide' ); 101 102 // Add support for editor styles. 103 add_theme_support( 'editor-styles' ); 104 105 // Enqueue editor styles. 106 add_editor_style( 'style-editor.css' ); 107 108 // Add custom editor font sizes. 109 add_theme_support( 110 'editor-font-sizes', 111 array( 112 array( 113 'name' => __( 'Small', 'twentynineteen' ), 114 'shortName' => __( 'S', 'twentynineteen' ), 115 'size' => 19.5, 116 'slug' => 'small', 117 ), 118 array( 119 'name' => __( 'Normal', 'twentynineteen' ), 120 'shortName' => __( 'M', 'twentynineteen' ), 121 'size' => 22, 122 'slug' => 'normal', 123 ), 124 array( 125 'name' => __( 'Large', 'twentynineteen' ), 126 'shortName' => __( 'L', 'twentynineteen' ), 127 'size' => 36.5, 128 'slug' => 'large', 129 ), 130 array( 131 'name' => __( 'Huge', 'twentynineteen' ), 132 'shortName' => __( 'XL', 'twentynineteen' ), 133 'size' => 49.5, 134 'slug' => 'huge', 135 ), 136 ) 137 ); 138 139 // Editor color palette. 140 add_theme_support( 141 'editor-color-palette', 142 array( 143 array( 144 'name' => 'default' === get_theme_mod( 'primary_color', 'default' ) ? __( 'Blue', 'twentynineteen' ) : null, 145 'slug' => 'primary', 146 'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 33 ), 147 ), 148 array( 149 'name' => 'default' === get_theme_mod( 'primary_color', 'default' ) ? __( 'Dark Blue', 'twentynineteen' ) : null, 150 'slug' => 'secondary', 151 'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? 199 : get_theme_mod( 'primary_color_hue', 199 ), 100, 23 ), 152 ), 153 array( 154 'name' => __( 'Dark Gray', 'twentynineteen' ), 155 'slug' => 'dark-gray', 156 'color' => '#111', 157 ), 158 array( 159 'name' => __( 'Light Gray', 'twentynineteen' ), 160 'slug' => 'light-gray', 161 'color' => '#767676', 162 ), 163 array( 164 'name' => __( 'White', 'twentynineteen' ), 165 'slug' => 'white', 166 'color' => '#FFF', 167 ), 168 ) 169 ); 170 171 // Add support for responsive embedded content. 172 add_theme_support( 'responsive-embeds' ); 173 174 // Add support for custom line height. 175 add_theme_support( 'custom-line-height' ); 176 } 177 endif; 178 add_action( 'after_setup_theme', 'twentynineteen_setup' ); 179 180 if ( ! function_exists( 'wp_get_list_item_separator' ) ) : 181 /** 182 * Retrieves the list item separator based on the locale. 183 * 184 * Added for backward compatibility to support pre-6.0.0 WordPress versions. 185 * 186 * @since Twenty Nineteen 2.3 187 * 188 * @return string Locale-specific list item separator. 189 */ 190 function wp_get_list_item_separator() { 191 /* translators: Used between list items, there is a space after the comma. */ 192 return __( ', ', 'twentynineteen' ); 193 } 194 endif; 195 196 /** 197 * Registers widget area. 198 * 199 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar 200 */ 201 function twentynineteen_widgets_init() { 202 203 register_sidebar( 204 array( 205 'name' => __( 'Footer', 'twentynineteen' ), 206 'id' => 'sidebar-1', 207 'description' => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ), 208 'before_widget' => '<section id="%1$s" class="widget %2$s">', 209 'after_widget' => '</section>', 210 'before_title' => '<h2 class="widget-title">', 211 'after_title' => '</h2>', 212 ) 213 ); 214 } 215 add_action( 'widgets_init', 'twentynineteen_widgets_init' ); 216 217 /** 218 * Replaces "[...]" (appended to automatically generated excerpts) with ... and 219 * a 'Continue reading' link. 220 * 221 * @since Twenty Nineteen 2.0 222 * 223 * @param string $link Link to single post/page. 224 * @return string 'Continue reading' link prepended with an ellipsis. 225 */ 226 function twentynineteen_excerpt_more( $link ) { 227 if ( is_admin() ) { 228 return $link; 229 } 230 231 $link = sprintf( 232 '<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>', 233 esc_url( get_permalink( get_the_ID() ) ), 234 /* translators: %s: Post title. Only visible to screen readers. */ 235 sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentynineteen' ), get_the_title( get_the_ID() ) ) 236 ); 237 return ' … ' . $link; 238 } 239 add_filter( 'excerpt_more', 'twentynineteen_excerpt_more' ); 240 241 /** 242 * Sets the content width in pixels, based on the theme's design and stylesheet. 243 * 244 * Priority 0 to make it available to lower priority callbacks. 245 * 246 * @global int $content_width Content width. 247 */ 248 function twentynineteen_content_width() { 249 /** 250 * Filters Twenty Nineteen content width of the theme. 251 * 252 * @since Twenty Nineteen 1.0 253 * 254 * @param int $content_width Content width in pixels. 255 */ 256 $GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 ); 257 } 258 add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 ); 259 260 /** 261 * Enqueues scripts and styles. 262 * 263 * @since Twenty Nineteen 1.0 264 */ 265 function twentynineteen_scripts() { 266 wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) ); 267 268 wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' ); 269 270 if ( has_nav_menu( 'menu-1' ) ) { 271 wp_enqueue_script( 272 'twentynineteen-priority-menu', 273 get_theme_file_uri( '/js/priority-menu.js' ), 274 array(), 275 '20200129', 276 array( 277 'in_footer' => false, // Because involves header. 278 'strategy' => 'defer', 279 ) 280 ); 281 wp_enqueue_script( 282 'twentynineteen-touch-navigation', 283 get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), 284 array(), 285 '20250802', 286 array( 287 'in_footer' => true, 288 'strategy' => 'defer', 289 ) 290 ); 291 } 292 293 wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' ); 294 295 if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { 296 wp_enqueue_script( 'comment-reply' ); 297 } 298 } 299 add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' ); 300 301 /** 302 * Fixes skip link focus in IE11. 303 * 304 * This does not enqueue the script because it is tiny and because it is only for IE11, 305 * thus it does not warrant having an entire dedicated blocking script being loaded. 306 * 307 * @since Twenty Nineteen 1.0 308 * @deprecated Twenty Nineteen 2.6 Removed from wp_print_footer_scripts action. 309 * 310 * @link https://git.io/vWdr2 311 */ 312 function twentynineteen_skip_link_focus_fix() { 313 // The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`. 314 ?> 315 <script> 316 /(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); 317 </script> 318 <?php 319 } 320 321 /** 322 * Enqueues supplemental block editor styles. 323 */ 324 function twentynineteen_editor_customizer_styles() { 325 326 wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '2.1', 'all' ); 327 328 if ( 'custom' === get_theme_mod( 'primary_color' ) ) { 329 // Include color patterns. 330 require_once get_parent_theme_file_path( '/inc/color-patterns.php' ); 331 wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() ); 332 } 333 } 334 add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' ); 335 336 /** 337 * Displays custom color CSS in customizer and on frontend. 338 */ 339 function twentynineteen_colors_css_wrap() { 340 341 // Only include custom colors in customizer or frontend. 342 if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'primary_color', 'default' ) ) || is_admin() ) { 343 return; 344 } 345 346 require_once get_parent_theme_file_path( '/inc/color-patterns.php' ); 347 348 $primary_color = 199; 349 if ( 'default' !== get_theme_mod( 'primary_color', 'default' ) ) { 350 $primary_color = get_theme_mod( 'primary_color_hue', 199 ); 351 } 352 ?> 353 354 <style id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . absint( $primary_color ) . '"' : ''; ?>> 355 <?php echo twentynineteen_custom_colors_css(); ?> 356 </style> 357 <?php 358 } 359 add_action( 'wp_head', 'twentynineteen_colors_css_wrap' ); 360 361 /** 362 * SVG Icons class. 363 */ 364 require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php'; 365 366 /** 367 * Custom Comment Walker template. 368 */ 369 require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php'; 370 371 /** 372 * Common theme functions. 373 */ 374 require get_template_directory() . '/inc/helper-functions.php'; 375 376 /** 377 * SVG Icons related functions. 378 */ 379 require get_template_directory() . '/inc/icon-functions.php'; 380 381 /** 382 * Enhance the theme by hooking into WordPress. 383 */ 384 require get_template_directory() . '/inc/template-functions.php'; 385 386 /** 387 * Custom template tags for the theme. 388 */ 389 require get_template_directory() . '/inc/template-tags.php'; 390 391 /** 392 * Customizer additions. 393 */ 394 require get_template_directory() . '/inc/customizer.php'; 395 396 /** 397 * Registers block patterns and pattern categories. 398 * 399 * @since Twenty Nineteen 3.0 400 */ 401 function twentynineteen_register_block_patterns() { 402 require get_template_directory() . '/inc/block-patterns.php'; 403 } 404 405 add_action( 'init', 'twentynineteen_register_block_patterns' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Thu Jun 18 08:20:10 2026 | Cross-referenced by PHPXref |