[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Twenty Fourteen functions and definitions
   4   *
   5   * Sets up the theme and provides some helper functions, which are used in the
   6   * theme as custom template tags. Others are attached to action and filter
   7   * hooks in WordPress to change core functionality.
   8   *
   9   * When using a child theme you can override certain functions (those wrapped
  10   * in a function_exists() call) by defining them first in your child theme's
  11   * functions.php file. The child theme's functions.php file is included before
  12   * the parent theme's file, so the child theme functions would be used.
  13   *
  14   * @link https://developer.wordpress.org/themes/basics/theme-functions/
  15   * @link https://developer.wordpress.org/themes/advanced-topics/child-themes/
  16   *
  17   * Functions that are not pluggable (not wrapped in function_exists()) are
  18   * instead attached to a filter or action hook.
  19   *
  20   * For more information on hooks, actions, and filters,
  21   * @link https://developer.wordpress.org/plugins/
  22   *
  23   * @package WordPress
  24   * @subpackage Twenty_Fourteen
  25   * @since Twenty Fourteen 1.0
  26   */
  27  
  28  /**
  29   * Set up the content width value based on the theme's design.
  30   *
  31   * @see twentyfourteen_content_width()
  32   *
  33   * @since Twenty Fourteen 1.0
  34   */
  35  if ( ! isset( $content_width ) ) {
  36      $content_width = 474;
  37  }
  38  
  39  /**
  40   * Twenty Fourteen only works in WordPress 3.6 or later.
  41   *
  42   * @global string $wp_version The WordPress version string.
  43   */
  44  if ( version_compare( $GLOBALS['wp_version'], '3.6', '<' ) ) {
  45      require get_template_directory() . '/inc/back-compat.php';
  46  }
  47  
  48  if ( ! function_exists( 'twentyfourteen_setup' ) ) :
  49      /**
  50       * Twenty Fourteen setup.
  51       *
  52       * Set up theme defaults and registers support for various WordPress features.
  53       *
  54       * Note that this function is hooked into the after_setup_theme hook, which
  55       * runs before the init hook. The init hook is too late for some features, such
  56       * as indicating support post thumbnails.
  57       *
  58       * @since Twenty Fourteen 1.0
  59       *
  60       * @global string $wp_version The WordPress version string.
  61       */
  62  	function twentyfourteen_setup() {
  63  
  64          /*
  65           * Make Twenty Fourteen available for translation.
  66           *
  67           * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyfourteen
  68           * If you're building a theme based on Twenty Fourteen, use a find and
  69           * replace to change 'twentyfourteen' to the name of your theme in all
  70           * template files.
  71           *
  72           * Manual loading of text domain is not required after the introduction of
  73           * just in time translation loading in WordPress version 4.6.
  74           *
  75           * @ticket 58318
  76           */
  77          if ( version_compare( $GLOBALS['wp_version'], '4.6', '<' ) ) {
  78              load_theme_textdomain( 'twentyfourteen' );
  79          }
  80  
  81          /*
  82           * This theme styles the visual editor to resemble the theme style.
  83           * When fonts are self-hosted, the theme directory needs to be removed first.
  84           */
  85          $font_stylesheet = str_replace(
  86              array( get_template_directory_uri() . '/', get_stylesheet_directory_uri() . '/' ),
  87              '',
  88              (string) twentyfourteen_font_url()
  89          );
  90          add_editor_style( array( 'css/editor-style.css', $font_stylesheet, 'genericons/genericons.css' ) );
  91  
  92          // Load regular editor styles into the new block-based editor.
  93          add_theme_support( 'editor-styles' );
  94  
  95          // Load default block styles.
  96          add_theme_support( 'wp-block-styles' );
  97  
  98          // Add support for responsive embeds.
  99          add_theme_support( 'responsive-embeds' );
 100  
 101          // Add support for custom color scheme.
 102          add_theme_support(
 103              'editor-color-palette',
 104              array(
 105                  array(
 106                      'name'  => __( 'Green', 'twentyfourteen' ),
 107                      'slug'  => 'green',
 108                      'color' => '#24890d',
 109                  ),
 110                  array(
 111                      'name'  => __( 'Black', 'twentyfourteen' ),
 112                      'slug'  => 'black',
 113                      'color' => '#000',
 114                  ),
 115                  array(
 116                      'name'  => __( 'Dark Gray', 'twentyfourteen' ),
 117                      'slug'  => 'dark-gray',
 118                      'color' => '#2b2b2b',
 119                  ),
 120                  array(
 121                      'name'  => __( 'Medium Gray', 'twentyfourteen' ),
 122                      'slug'  => 'medium-gray',
 123                      'color' => '#767676',
 124                  ),
 125                  array(
 126                      'name'  => __( 'Light Gray', 'twentyfourteen' ),
 127                      'slug'  => 'light-gray',
 128                      'color' => '#f5f5f5',
 129                  ),
 130                  array(
 131                      'name'  => __( 'White', 'twentyfourteen' ),
 132                      'slug'  => 'white',
 133                      'color' => '#fff',
 134                  ),
 135              )
 136          );
 137  
 138          // Add RSS feed links to <head> for posts and comments.
 139          add_theme_support( 'automatic-feed-links' );
 140  
 141          // Enable support for Post Thumbnails, and declare two sizes.
 142          add_theme_support( 'post-thumbnails' );
 143          set_post_thumbnail_size( 672, 372, true );
 144          add_image_size( 'twentyfourteen-full-width', 1038, 576, true );
 145  
 146          // This theme uses wp_nav_menu() in two locations.
 147          register_nav_menus(
 148              array(
 149                  'primary'   => __( 'Top primary menu', 'twentyfourteen' ),
 150                  'secondary' => __( 'Secondary menu in left sidebar', 'twentyfourteen' ),
 151              )
 152          );
 153  
 154          /*
 155           * Switch default core markup for search form, comment form, and comments
 156           * to output valid HTML5.
 157           */
 158          add_theme_support(
 159              'html5',
 160              array(
 161                  'search-form',
 162                  'comment-form',
 163                  'comment-list',
 164                  'gallery',
 165                  'caption',
 166                  'script',
 167                  'style',
 168                  'navigation-widgets',
 169              )
 170          );
 171  
 172          /*
 173           * Enable support for Post Formats.
 174           * See: https://developer.wordpress.org/advanced-administration/wordpress/post-formats/
 175           */
 176          add_theme_support(
 177              'post-formats',
 178              array(
 179                  'aside',
 180                  'image',
 181                  'video',
 182                  'audio',
 183                  'quote',
 184                  'link',
 185                  'gallery',
 186              )
 187          );
 188  
 189          // This theme allows users to set a custom background.
 190          add_theme_support(
 191              'custom-background',
 192              /**
 193               * Filters Twenty Fourteen custom-background support arguments.
 194               *
 195               * @since Twenty Fourteen 1.0
 196               *
 197               * @param array $args {
 198               *     An array of custom-background support arguments.
 199               *
 200               *     @type string $default-color Default color of the background.
 201               * }
 202               */
 203              apply_filters(
 204                  'twentyfourteen_custom_background_args',
 205                  array(
 206                      'default-color' => 'f5f5f5',
 207                  )
 208              )
 209          );
 210  
 211          // Add support for featured content.
 212          add_theme_support(
 213              'featured-content',
 214              array(
 215                  'featured_content_filter' => 'twentyfourteen_get_featured_posts',
 216                  'max_posts'               => 6,
 217              )
 218          );
 219  
 220          // This theme uses its own gallery styles.
 221          add_filter( 'use_default_gallery_style', '__return_false' );
 222  
 223          // Indicate widget sidebars can use selective refresh in the Customizer.
 224          add_theme_support( 'customize-selective-refresh-widgets' );
 225      }
 226  endif; // twentyfourteen_setup()
 227  add_action( 'after_setup_theme', 'twentyfourteen_setup' );
 228  
 229  /**
 230   * Adjusts content_width value for image attachment template.
 231   *
 232   * @since Twenty Fourteen 1.0
 233   *
 234   * @global int $content_width Content width.
 235   */
 236  function twentyfourteen_content_width() {
 237      if ( is_attachment() && wp_attachment_is_image() ) {
 238          $GLOBALS['content_width'] = 810;
 239      }
 240  }
 241  add_action( 'template_redirect', 'twentyfourteen_content_width' );
 242  
 243  /**
 244   * Getter function for Featured Content Plugin.
 245   *
 246   * @since Twenty Fourteen 1.0
 247   *
 248   * @return array An array of WP_Post objects.
 249   */
 250  function twentyfourteen_get_featured_posts() {
 251      /**
 252       * Filters the featured posts to return in Twenty Fourteen.
 253       *
 254       * @since Twenty Fourteen 1.0
 255       *
 256       * @param array|bool $posts Array of featured posts, otherwise false.
 257       */
 258      return apply_filters( 'twentyfourteen_get_featured_posts', array() );
 259  }
 260  
 261  /**
 262   * A helper conditional function that returns a boolean value.
 263   *
 264   * @since Twenty Fourteen 1.0
 265   *
 266   * @return bool Whether there are featured posts.
 267   */
 268  function twentyfourteen_has_featured_posts() {
 269      return ! is_paged() && (bool) twentyfourteen_get_featured_posts();
 270  }
 271  
 272  /**
 273   * Registers three Twenty Fourteen widget areas.
 274   *
 275   * @since Twenty Fourteen 1.0
 276   */
 277  function twentyfourteen_widgets_init() {
 278      require get_template_directory() . '/inc/widgets.php';
 279      register_widget( 'Twenty_Fourteen_Ephemera_Widget' );
 280  
 281      register_sidebar(
 282          array(
 283              'name'          => __( 'Primary Sidebar', 'twentyfourteen' ),
 284              'id'            => 'sidebar-1',
 285              'description'   => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ),
 286              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 287              'after_widget'  => '</aside>',
 288              'before_title'  => '<h1 class="widget-title">',
 289              'after_title'   => '</h1>',
 290          )
 291      );
 292      register_sidebar(
 293          array(
 294              'name'          => __( 'Content Sidebar', 'twentyfourteen' ),
 295              'id'            => 'sidebar-2',
 296              'description'   => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ),
 297              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 298              'after_widget'  => '</aside>',
 299              'before_title'  => '<h1 class="widget-title">',
 300              'after_title'   => '</h1>',
 301          )
 302      );
 303      register_sidebar(
 304          array(
 305              'name'          => __( 'Footer Widget Area', 'twentyfourteen' ),
 306              'id'            => 'sidebar-3',
 307              'description'   => __( 'Appears in the footer section of the site.', 'twentyfourteen' ),
 308              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 309              'after_widget'  => '</aside>',
 310              'before_title'  => '<h1 class="widget-title">',
 311              'after_title'   => '</h1>',
 312          )
 313      );
 314  }
 315  add_action( 'widgets_init', 'twentyfourteen_widgets_init' );
 316  
 317  if ( ! function_exists( 'twentyfourteen_font_url' ) ) :
 318      /**
 319       * Registers Lato font for Twenty Fourteen.
 320       *
 321       * @since Twenty Fourteen 1.0
 322       * @since Twenty Fourteen 3.6 Replaced Google URL with self-hosted fonts.
 323       *
 324       * @return string Font stylesheet URL or empty string if disabled.
 325       */
 326  	function twentyfourteen_font_url() {
 327          $font_url = '';
 328          /*
 329           * translators: If there are characters in your language that are not supported
 330           * by Lato, translate this to 'off'. Do not translate into your own language.
 331           */
 332          if ( 'off' !== _x( 'on', 'Lato font: on or off', 'twentyfourteen' ) ) {
 333              $font_url = get_template_directory_uri() . '/fonts/font-lato.css';
 334          }
 335  
 336          return $font_url;
 337      }
 338  endif;
 339  
 340  /**
 341   * Enqueues scripts and styles for the front end.
 342   *
 343   * @since Twenty Fourteen 1.0
 344   */
 345  function twentyfourteen_scripts() {
 346      // Add Lato font, used in the main stylesheet.
 347      $font_version = ( 0 === strpos( (string) twentyfourteen_font_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
 348      wp_enqueue_style( 'twentyfourteen-lato', twentyfourteen_font_url(), array(), $font_version );
 349  
 350      // Add Genericons font, used in the main stylesheet.
 351      wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '20251101' );
 352  
 353      // Load our main stylesheet.
 354      wp_enqueue_style( 'twentyfourteen-style', get_stylesheet_uri(), array(), '20260520' );
 355  
 356      // Theme block stylesheet.
 357      wp_enqueue_style( 'twentyfourteen-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'twentyfourteen-style' ), '20250715' );
 358  
 359      // Register the Internet Explorer specific stylesheet.
 360      wp_register_style( 'twentyfourteen-ie', false, array( 'twentyfourteen-style' ) );
 361  
 362      if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
 363          wp_enqueue_script( 'comment-reply' );
 364      }
 365  
 366      if ( is_singular() && wp_attachment_is_image() ) {
 367          wp_enqueue_script( 'twentyfourteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20150120' );
 368      }
 369  
 370      if ( is_active_sidebar( 'sidebar-3' ) ) {
 371          wp_enqueue_script( 'jquery-masonry' );
 372      }
 373  
 374      if ( is_front_page() && 'slider' === get_theme_mod( 'featured_content_layout' ) ) {
 375          wp_enqueue_script(
 376              'twentyfourteen-slider',
 377              get_template_directory_uri() . '/js/slider.js',
 378              array( 'jquery' ),
 379              '20150120',
 380              array(
 381                  'in_footer' => false, // Because involves header.
 382                  'strategy'  => 'defer',
 383              )
 384          );
 385          wp_localize_script(
 386              'twentyfourteen-slider',
 387              'featuredSliderDefaults',
 388              array(
 389                  'prevText' => __( 'Previous', 'twentyfourteen' ),
 390                  'nextText' => __( 'Next', 'twentyfourteen' ),
 391              )
 392          );
 393      }
 394  
 395      wp_enqueue_script(
 396          'twentyfourteen-script',
 397          get_template_directory_uri() . '/js/functions.js',
 398          array( 'jquery' ),
 399          '20250729',
 400          array(
 401              'in_footer' => false, // Because involves header.
 402              'strategy'  => 'defer',
 403          )
 404      );
 405  }
 406  add_action( 'wp_enqueue_scripts', 'twentyfourteen_scripts' );
 407  
 408  /**
 409   * Enqueues font stylesheet to admin screen for custom header display.
 410   *
 411   * @since Twenty Fourteen 1.0
 412   */
 413  function twentyfourteen_admin_fonts() {
 414      $font_version = ( 0 === strpos( (string) twentyfourteen_font_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
 415      wp_enqueue_style( 'twentyfourteen-lato', twentyfourteen_font_url(), array(), $font_version );
 416  }
 417  add_action( 'admin_print_scripts-appearance_page_custom-header', 'twentyfourteen_admin_fonts' );
 418  
 419  /**
 420   * Adds preconnect for Google Fonts.
 421   *
 422   * @since Twenty Fourteen 1.9
 423   * @deprecated Twenty Fourteen 3.6 Disabled filter because, by default, fonts are self-hosted.
 424   *
 425   * @global string $wp_version The WordPress version string.
 426   *
 427   * @param array   $urls          URLs to print for resource hints.
 428   * @param string  $relation_type The relation type the URLs are printed.
 429   * @return array URLs to print for resource hints.
 430   */
 431  function twentyfourteen_resource_hints( $urls, $relation_type ) {
 432      if ( wp_style_is( 'twentyfourteen-lato', 'queue' ) && 'preconnect' === $relation_type ) {
 433          if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
 434              $urls[] = array(
 435                  'href' => 'https://fonts.gstatic.com',
 436                  'crossorigin',
 437              );
 438          } else {
 439              $urls[] = 'https://fonts.gstatic.com';
 440          }
 441      }
 442  
 443      return $urls;
 444  }
 445  // add_filter( 'wp_resource_hints', 'twentyfourteen_resource_hints', 10, 2 );
 446  
 447  /**
 448   * Enqueues styles for the block-based editor.
 449   *
 450   * @since Twenty Fourteen 2.3
 451   */
 452  function twentyfourteen_block_editor_styles() {
 453      // Block styles.
 454      wp_enqueue_style( 'twentyfourteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20240716' );
 455      // Add custom fonts.
 456      $font_version = ( 0 === strpos( (string) twentyfourteen_font_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null;
 457      wp_enqueue_style( 'twentyfourteen-fonts', twentyfourteen_font_url(), array(), $font_version );
 458  }
 459  add_action( 'enqueue_block_editor_assets', 'twentyfourteen_block_editor_styles' );
 460  
 461  if ( ! function_exists( 'twentyfourteen_the_attached_image' ) ) :
 462      /**
 463       * Prints the attached image with a link to the next attached image.
 464       *
 465       * @since Twenty Fourteen 1.0
 466       */
 467  	function twentyfourteen_the_attached_image() {
 468          $post = get_post();
 469          /**
 470           * Filters the default Twenty Fourteen attachment size.
 471           *
 472           * @since Twenty Fourteen 1.0
 473           *
 474           * @param array $dimensions {
 475           *     An array of height and width dimensions.
 476           *
 477           *     @type int $height Height of the image in pixels. Default 810.
 478           *     @type int $width  Width of the image in pixels. Default 810.
 479           * }
 480           */
 481          $attachment_size     = apply_filters( 'twentyfourteen_attachment_size', array( 810, 810 ) );
 482          $next_attachment_url = wp_get_attachment_url();
 483  
 484          /*
 485           * Grab the IDs of all the image attachments in a gallery so we can get the URL
 486           * of the next adjacent image in a gallery, or the first image (if we're
 487           * looking at the last image in a gallery), or, in a gallery of one, just the
 488           * link to that image file.
 489           */
 490          $attachment_ids = get_posts(
 491              array(
 492                  'post_parent'    => $post->post_parent,
 493                  'fields'         => 'ids',
 494                  'numberposts'    => -1,
 495                  'post_status'    => 'inherit',
 496                  'post_type'      => 'attachment',
 497                  'post_mime_type' => 'image',
 498                  'order'          => 'ASC',
 499                  'orderby'        => 'menu_order ID',
 500              )
 501          );
 502  
 503          // If there is more than 1 attachment in a gallery...
 504          if ( count( $attachment_ids ) > 1 ) {
 505              foreach ( $attachment_ids as $idx => $attachment_id ) {
 506                  if ( $attachment_id === $post->ID ) {
 507                      $next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ];
 508                      break;
 509                  }
 510              }
 511  
 512              if ( $next_id ) {
 513                  // ...get the URL of the next image attachment.
 514                  $next_attachment_url = get_attachment_link( $next_id );
 515              } else {
 516                  // ...or get the URL of the first image attachment.
 517                  $next_attachment_url = get_attachment_link( reset( $attachment_ids ) );
 518              }
 519          }
 520  
 521          printf(
 522              '<a href="%1$s" rel="attachment">%2$s</a>',
 523              esc_url( $next_attachment_url ),
 524              wp_get_attachment_image( $post->ID, $attachment_size )
 525          );
 526      }
 527  endif;
 528  
 529  if ( ! function_exists( 'twentyfourteen_list_authors' ) ) :
 530      /**
 531       * Prints a list of all site contributors who published at least one post.
 532       *
 533       * @since Twenty Fourteen 1.0
 534       *
 535       * @global string $wp_version The WordPress version string.
 536       */
 537  	function twentyfourteen_list_authors() {
 538          $args = array(
 539              'fields'     => 'ID',
 540              'orderby'    => 'post_count',
 541              'order'      => 'DESC',
 542              'capability' => array( 'edit_posts' ),
 543          );
 544  
 545          // Capability queries were only introduced in WP 5.9.
 546          if ( version_compare( $GLOBALS['wp_version'], '5.9-alpha', '<' ) ) {
 547              $args['who'] = 'authors';
 548              unset( $args['capability'] );
 549          }
 550  
 551          /**
 552           * Filters query arguments for listing authors.
 553           *
 554           * @since Twenty Fourteen 3.3
 555           *
 556           * @param array $args Query arguments.
 557           */
 558          $args = apply_filters( 'twentyfourteen_list_authors_query_args', $args );
 559  
 560          $contributor_ids = get_users( $args );
 561  
 562          foreach ( $contributor_ids as $contributor_id ) :
 563              $post_count = count_user_posts( $contributor_id );
 564  
 565              // Move on if user has not published a post (yet).
 566              if ( ! $post_count ) {
 567                  continue;
 568              }
 569              ?>
 570  
 571          <div class="contributor">
 572          <div class="contributor-info">
 573              <div class="contributor-avatar"><?php echo get_avatar( $contributor_id, 132 ); ?></div>
 574              <div class="contributor-summary">
 575                  <h2 class="contributor-name"><?php echo get_the_author_meta( 'display_name', $contributor_id ); ?></h2>
 576                  <p class="contributor-bio">
 577                      <?php echo get_the_author_meta( 'description', $contributor_id ); ?>
 578                  </p>
 579                  <a class="button contributor-posts-link" href="<?php echo esc_url( get_author_posts_url( $contributor_id ) ); ?>">
 580                      <?php
 581                      /* translators: %d: Post count. */
 582                      printf( _n( '%d Article', '%d Articles', $post_count, 'twentyfourteen' ), $post_count );
 583                      ?>
 584                  </a>
 585              </div><!-- .contributor-summary -->
 586          </div><!-- .contributor-info -->
 587      </div><!-- .contributor -->
 588  
 589              <?php
 590      endforeach;
 591      }
 592  endif;
 593  
 594  /**
 595   * Extends the default WordPress body classes.
 596   *
 597   * Adds body classes to denote:
 598   * 1. Single or multiple authors.
 599   * 2. Presence of header image except in Multisite signup and activate pages.
 600   * 3. Index views.
 601   * 4. Full-width content layout.
 602   * 5. Presence of footer widgets.
 603   * 6. Single views.
 604   * 7. Featured content layout.
 605   *
 606   * @since Twenty Fourteen 1.0
 607   *
 608   * @global string $pagenow The filename of the current screen.
 609   *
 610   * @param array $classes A list of existing body class values.
 611   * @return array The filtered body class list.
 612   */
 613  function twentyfourteen_body_classes( $classes ) {
 614      if ( is_multi_author() ) {
 615          $classes[] = 'group-blog';
 616      }
 617  
 618      if ( get_header_image() ) {
 619          $classes[] = 'header-image';
 620      } elseif ( ! in_array( $GLOBALS['pagenow'], array( 'wp-activate.php', 'wp-signup.php' ), true ) ) {
 621          $classes[] = 'masthead-fixed';
 622      }
 623  
 624      if ( is_archive() || is_search() || is_home() ) {
 625          $classes[] = 'list-view';
 626      }
 627  
 628      if ( ( ! is_active_sidebar( 'sidebar-2' ) )
 629          || is_page_template( 'page-templates/full-width.php' )
 630          || is_page_template( 'page-templates/contributors.php' )
 631          || is_attachment() ) {
 632          $classes[] = 'full-width';
 633      }
 634  
 635      if ( is_active_sidebar( 'sidebar-3' ) ) {
 636          $classes[] = 'footer-widgets';
 637      }
 638  
 639      if ( is_singular() && ! is_front_page() ) {
 640          $classes[] = 'singular';
 641      }
 642  
 643      if ( is_front_page() && 'slider' === get_theme_mod( 'featured_content_layout' ) ) {
 644          $classes[] = 'slider';
 645      } elseif ( is_front_page() ) {
 646          $classes[] = 'grid';
 647      }
 648  
 649      return $classes;
 650  }
 651  add_filter( 'body_class', 'twentyfourteen_body_classes' );
 652  
 653  /**
 654   * Extends the default WordPress post classes.
 655   *
 656   * Adds a post class to denote:
 657   * Non-password protected page with a post thumbnail.
 658   *
 659   * @since Twenty Fourteen 1.0
 660   *
 661   * @param array $classes A list of existing post class values.
 662   * @return array The filtered post class list.
 663   */
 664  function twentyfourteen_post_classes( $classes ) {
 665      if ( ! post_password_required() && ! is_attachment() && has_post_thumbnail() ) {
 666          $classes[] = 'has-post-thumbnail';
 667      }
 668  
 669      return $classes;
 670  }
 671  add_filter( 'post_class', 'twentyfourteen_post_classes' );
 672  
 673  /**
 674   * Creates a nicely formatted and more specific title element text for output
 675   * in head of document, based on current view.
 676   *
 677   * @since Twenty Fourteen 1.0
 678   *
 679   * @global int $paged Page number of a list of posts.
 680   * @global int $page  Page number of a single post.
 681   *
 682   * @param string $title Default title text for current view.
 683   * @param string $sep Optional separator.
 684   * @return string The filtered title.
 685   */
 686  function twentyfourteen_wp_title( $title, $sep ) {
 687      global $paged, $page;
 688  
 689      if ( is_feed() ) {
 690          return $title;
 691      }
 692  
 693      // Add the site name.
 694      $title .= get_bloginfo( 'name', 'display' );
 695  
 696      // Add the site description for the home/front page.
 697      $site_description = get_bloginfo( 'description', 'display' );
 698      if ( $site_description && ( is_home() || is_front_page() ) ) {
 699          $title = "$title $sep $site_description";
 700      }
 701  
 702      // Add a page number if necessary.
 703      if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
 704          /* translators: %s: Page number. */
 705          $title = "$title $sep " . sprintf( __( 'Page %s', 'twentyfourteen' ), max( $paged, $page ) );
 706      }
 707  
 708      return $title;
 709  }
 710  add_filter( 'wp_title', 'twentyfourteen_wp_title', 10, 2 );
 711  
 712  
 713  /**
 714   * Modifies tag cloud widget arguments to display all tags in the same font size
 715   * and use list format for better accessibility.
 716   *
 717   * @since Twenty Fourteen 2.1
 718   *
 719   * @param array $args Arguments for tag cloud widget.
 720   * @return array The filtered arguments for tag cloud widget.
 721   */
 722  function twentyfourteen_widget_tag_cloud_args( $args ) {
 723      $args['largest']  = 22;
 724      $args['smallest'] = 8;
 725      $args['unit']     = 'pt';
 726      $args['format']   = 'list';
 727  
 728      return $args;
 729  }
 730  add_filter( 'widget_tag_cloud_args', 'twentyfourteen_widget_tag_cloud_args' );
 731  
 732  
 733  // Implement Custom Header features.
 734  require get_template_directory() . '/inc/custom-header.php';
 735  
 736  // Custom template tags for this theme.
 737  require get_template_directory() . '/inc/template-tags.php';
 738  
 739  // Add Customizer functionality.
 740  require get_template_directory() . '/inc/customizer.php';
 741  
 742  /**
 743   * Registers block patterns and pattern categories.
 744   *
 745   * @since Twenty Fourteen 4.1
 746   */
 747  function twentyfourteen_register_block_patterns() {
 748      require get_template_directory() . '/inc/block-patterns.php';
 749  }
 750  
 751  add_action( 'init', 'twentyfourteen_register_block_patterns' );
 752  
 753  /*
 754   * Add Featured Content functionality.
 755   *
 756   * To overwrite in a plugin, define your own Featured_Content class on or
 757   * before the 'setup_theme' hook.
 758   *
 759   * @global string $pagenow The filename of the current screen.
 760   */
 761  if ( ! class_exists( 'Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {
 762      require get_template_directory() . '/inc/featured-content.php';
 763  }
 764  
 765  /**
 766   * Adds an `is_customize_preview` function if it is missing.
 767   *
 768   * Enables installing Twenty Fourteen in WordPress versions before 4.0.0 when the
 769   * `is_customize_preview` function was introduced.
 770   *
 771   * @global WP_Customize_Manager $wp_customize Customizer object.
 772   *
 773   * @return bool Whether the site is being previewed in the Customizer.
 774   */
 775  if ( ! function_exists( 'is_customize_preview' ) ) :
 776  	function is_customize_preview() {
 777          global $wp_customize;
 778  
 779          return ( $wp_customize instanceof WP_Customize_Manager ) && $wp_customize->is_preview();
 780      }
 781  endif;


Generated : Mon Jun 15 08:20:09 2026 Cross-referenced by PHPXref