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


Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref