[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Twenty Eleven functions and definitions
   4   *
   5   * Sets up the theme and provides some helper functions. Some helper functions
   6   * are used in the theme as custom template tags. Others are attached to action and
   7   * filter hooks in WordPress to change core functionality.
   8   *
   9   * The first function, twentyeleven_setup(), sets up the theme by registering support
  10   * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
  11   *
  12   * When using a child theme you can override certain functions (those wrapped
  13   * in a function_exists() call) by defining them first in your child theme's
  14   * functions.php file. The child theme's functions.php file is included before
  15   * the parent theme's file, so the child theme functions would be used.
  16   *
  17   * @link https://developer.wordpress.org/themes/basics/theme-functions/
  18   * @link https://developer.wordpress.org/themes/advanced-topics/child-themes/
  19   *
  20   * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
  21   * to a filter or action hook. The hook can be removed by using remove_action() or
  22   * remove_filter() and you can attach your own function to the hook.
  23   *
  24   * We can remove the parent theme's hook only after it is attached, which means we need to
  25   * wait until setting up the child theme:
  26   *
  27   * <code>
  28   * add_action( 'after_setup_theme', 'my_child_theme_setup' );
  29   * function my_child_theme_setup() {
  30   *     // We are providing our own filter for excerpt_length (or using the unfiltered value).
  31   *     remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
  32   *     ...
  33   * }
  34   * </code>
  35   *
  36   * For more information on hooks, actions, and filters, see https://developer.wordpress.org/plugins/.
  37   *
  38   * @package WordPress
  39   * @subpackage Twenty_Eleven
  40   * @since Twenty Eleven 1.0
  41   */
  42  
  43  // Set the content width based on the theme's design and stylesheet.
  44  if ( ! isset( $content_width ) ) {
  45      $content_width = 584;
  46  }
  47  
  48  /*
  49   * Tell WordPress to run twentyeleven_setup() when the 'after_setup_theme' hook is run.
  50   */
  51  add_action( 'after_setup_theme', 'twentyeleven_setup' );
  52  
  53  if ( ! function_exists( 'twentyeleven_setup' ) ) :
  54      /**
  55       * Sets up theme defaults and registers support for various WordPress features.
  56       *
  57       * Note that this function is hooked into the after_setup_theme hook, which runs
  58       * before the init hook. The init hook is too late for some features, such as indicating
  59       * support post thumbnails.
  60       *
  61       * To override twentyeleven_setup() in a child theme, add your own twentyeleven_setup to your child theme's
  62       * functions.php file.
  63       *
  64       * @uses load_theme_textdomain()    For translation/localization support.
  65       * @uses add_editor_style()         To style the visual editor.
  66       * @uses add_theme_support()        To add support for post thumbnails, automatic feed links, custom headers
  67       *                                  and backgrounds, and post formats.
  68       * @uses register_nav_menus()       To add support for navigation menus.
  69       * @uses register_default_headers() To register the default custom header images provided with the theme.
  70       * @uses set_post_thumbnail_size()  To set a custom post thumbnail size.
  71       *
  72       * @since Twenty Eleven 1.0
  73       *
  74       * @global string $wp_version The WordPress version string.
  75       */
  76  	function twentyeleven_setup() {
  77  
  78          /*
  79           * Make Twenty Eleven available for translation.
  80           * Translations can be added to the /languages/ directory.
  81           * If you're building a theme based on Twenty Eleven, use
  82           * a find and replace to change 'twentyeleven' to the name
  83           * of your theme in all the template files.
  84           *
  85           * Manual loading of text domain is not required after the introduction of
  86           * just in time translation loading in WordPress version 4.6.
  87           *
  88           * @ticket 58318
  89           */
  90          if ( version_compare( $GLOBALS['wp_version'], '4.6', '<' ) ) {
  91              load_theme_textdomain( 'twentyeleven', get_template_directory() . '/languages' );
  92          }
  93  
  94          // This theme styles the visual editor with editor-style.css to match the theme style.
  95          add_editor_style();
  96  
  97          // Load regular editor styles into the new block-based editor.
  98          add_theme_support( 'editor-styles' );
  99  
 100          // Load default block styles.
 101          add_theme_support( 'wp-block-styles' );
 102  
 103          // Add support for responsive embeds.
 104          add_theme_support( 'responsive-embeds' );
 105  
 106          // Add support for custom color scheme.
 107          add_theme_support(
 108              'editor-color-palette',
 109              array(
 110                  array(
 111                      'name'  => __( 'Blue', 'twentyeleven' ),
 112                      'slug'  => 'blue',
 113                      'color' => '#1982d1',
 114                  ),
 115                  array(
 116                      'name'  => __( 'Black', 'twentyeleven' ),
 117                      'slug'  => 'black',
 118                      'color' => '#000',
 119                  ),
 120                  array(
 121                      'name'  => __( 'Dark Gray', 'twentyeleven' ),
 122                      'slug'  => 'dark-gray',
 123                      'color' => '#373737',
 124                  ),
 125                  array(
 126                      'name'  => __( 'Medium Gray', 'twentyeleven' ),
 127                      'slug'  => 'medium-gray',
 128                      'color' => '#666',
 129                  ),
 130                  array(
 131                      'name'  => __( 'Light Gray', 'twentyeleven' ),
 132                      'slug'  => 'light-gray',
 133                      'color' => '#e2e2e2',
 134                  ),
 135                  array(
 136                      'name'  => __( 'White', 'twentyeleven' ),
 137                      'slug'  => 'white',
 138                      'color' => '#fff',
 139                  ),
 140              )
 141          );
 142  
 143          // Load up our theme options page and related code.
 144          require get_template_directory() . '/inc/theme-options.php';
 145  
 146          // Grab Twenty Eleven's Ephemera widget.
 147          require get_template_directory() . '/inc/widgets.php';
 148  
 149          // Load block patterns.
 150          require get_template_directory() . '/inc/block-patterns.php';
 151  
 152          // Add default posts and comments RSS feed links to <head>.
 153          add_theme_support( 'automatic-feed-links' );
 154  
 155          // This theme uses wp_nav_menu() in one location.
 156          register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) );
 157  
 158          // Add support for a variety of post formats.
 159          add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) );
 160  
 161          $theme_options = twentyeleven_get_theme_options();
 162          if ( 'dark' === $theme_options['color_scheme'] ) {
 163              $default_background_color = '1d1d1d';
 164          } else {
 165              $default_background_color = 'e2e2e2';
 166          }
 167  
 168          // Add support for custom backgrounds.
 169          add_theme_support(
 170              'custom-background',
 171              array(
 172                  /*
 173                  * Let WordPress know what our default background color is.
 174                  * This is dependent on our current color scheme.
 175                  */
 176                  'default-color' => $default_background_color,
 177              )
 178          );
 179  
 180          // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images.
 181          add_theme_support( 'post-thumbnails' );
 182  
 183          // Add support for custom headers.
 184          $custom_header_support = array(
 185              // The default header text color.
 186              'default-text-color'     => '000',
 187              // The height and width of our custom header.
 188              /**
 189               * Filters the Twenty Eleven default header image width.
 190               *
 191               * @since Twenty Eleven 1.0
 192               *
 193               * @param int $width The default header image width in pixels. Default 1000.
 194               */
 195              'width'                  => apply_filters( 'twentyeleven_header_image_width', 1000 ),
 196              /**
 197               * Filters the Twenty Eleven default header image height.
 198               *
 199               * @since Twenty Eleven 1.0
 200               *
 201               * @param int $height The default header image height in pixels. Default 288.
 202               */
 203              'height'                 => apply_filters( 'twentyeleven_header_image_height', 288 ),
 204              // Support flexible heights.
 205              'flex-height'            => true,
 206              // Random image rotation by default.
 207              'random-default'         => true,
 208              // Callback for styling the header.
 209              'wp-head-callback'       => 'twentyeleven_header_style',
 210              // Callback for styling the header preview in the admin.
 211              'admin-head-callback'    => 'twentyeleven_admin_header_style',
 212              // Callback used to display the header preview in the admin.
 213              'admin-preview-callback' => 'twentyeleven_admin_header_image',
 214          );
 215  
 216          add_theme_support( 'custom-header', $custom_header_support );
 217  
 218          if ( ! function_exists( 'get_custom_header' ) ) {
 219              // This is all for compatibility with versions of WordPress prior to 3.4.
 220              define( 'HEADER_TEXTCOLOR', $custom_header_support['default-text-color'] );
 221              define( 'HEADER_IMAGE', '' );
 222              define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] );
 223              define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] );
 224              add_custom_image_header( $custom_header_support['wp-head-callback'], $custom_header_support['admin-head-callback'], $custom_header_support['admin-preview-callback'] );
 225              add_custom_background();
 226          }
 227  
 228          /*
 229           * We'll be using post thumbnails for custom header images on posts and pages.
 230           * We want them to be the size of the header image that we just defined.
 231           * Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
 232           */
 233          set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true );
 234  
 235          /*
 236           * Add Twenty Eleven's custom image sizes.
 237           * Used for large feature (header) images.
 238           */
 239          add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true );
 240          // Used for featured posts if a large-feature doesn't exist.
 241          add_image_size( 'small-feature', 500, 300 );
 242  
 243          // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
 244          register_default_headers(
 245              array(
 246                  'wheel'      => array(
 247                      'url'           => '%s/images/headers/wheel.jpg',
 248                      'thumbnail_url' => '%s/images/headers/wheel-thumbnail.jpg',
 249                      /* translators: Header image description. */
 250                      'description'   => __( 'Wheel', 'twentyeleven' ),
 251                  ),
 252                  'shore'      => array(
 253                      'url'           => '%s/images/headers/shore.jpg',
 254                      'thumbnail_url' => '%s/images/headers/shore-thumbnail.jpg',
 255                      /* translators: Header image description. */
 256                      'description'   => __( 'Shore', 'twentyeleven' ),
 257                  ),
 258                  'trolley'    => array(
 259                      'url'           => '%s/images/headers/trolley.jpg',
 260                      'thumbnail_url' => '%s/images/headers/trolley-thumbnail.jpg',
 261                      /* translators: Header image description. */
 262                      'description'   => __( 'Trolley', 'twentyeleven' ),
 263                  ),
 264                  'pine-cone'  => array(
 265                      'url'           => '%s/images/headers/pine-cone.jpg',
 266                      'thumbnail_url' => '%s/images/headers/pine-cone-thumbnail.jpg',
 267                      /* translators: Header image description. */
 268                      'description'   => __( 'Pine Cone', 'twentyeleven' ),
 269                  ),
 270                  'chessboard' => array(
 271                      'url'           => '%s/images/headers/chessboard.jpg',
 272                      'thumbnail_url' => '%s/images/headers/chessboard-thumbnail.jpg',
 273                      /* translators: Header image description. */
 274                      'description'   => __( 'Chessboard', 'twentyeleven' ),
 275                  ),
 276                  'lanterns'   => array(
 277                      'url'           => '%s/images/headers/lanterns.jpg',
 278                      'thumbnail_url' => '%s/images/headers/lanterns-thumbnail.jpg',
 279                      /* translators: Header image description. */
 280                      'description'   => __( 'Lanterns', 'twentyeleven' ),
 281                  ),
 282                  'willow'     => array(
 283                      'url'           => '%s/images/headers/willow.jpg',
 284                      'thumbnail_url' => '%s/images/headers/willow-thumbnail.jpg',
 285                      /* translators: Header image description. */
 286                      'description'   => __( 'Willow', 'twentyeleven' ),
 287                  ),
 288                  'hanoi'      => array(
 289                      'url'           => '%s/images/headers/hanoi.jpg',
 290                      'thumbnail_url' => '%s/images/headers/hanoi-thumbnail.jpg',
 291                      /* translators: Header image description. */
 292                      'description'   => __( 'Hanoi Plant', 'twentyeleven' ),
 293                  ),
 294              )
 295          );
 296  
 297          // Indicate widget sidebars can use selective refresh in the Customizer.
 298          add_theme_support( 'customize-selective-refresh-widgets' );
 299      }
 300  endif; // twentyeleven_setup()
 301  
 302  /**
 303   * Enqueues scripts and styles for front end.
 304   *
 305   * @since Twenty Eleven 2.9
 306   */
 307  function twentyeleven_scripts_styles() {
 308      // Theme block stylesheet.
 309      wp_enqueue_style( 'twentyeleven-block-style', get_template_directory_uri() . '/blocks.css', array(), '20240703' );
 310  }
 311  add_action( 'wp_enqueue_scripts', 'twentyeleven_scripts_styles' );
 312  
 313  /**
 314   * Enqueues styles for the block-based editor.
 315   *
 316   * @since Twenty Eleven 2.9
 317   */
 318  function twentyeleven_block_editor_styles() {
 319      // Block styles.
 320      wp_enqueue_style( 'twentyeleven-block-editor-style', get_template_directory_uri() . '/editor-blocks.css', array(), '20240716' );
 321  }
 322  add_action( 'enqueue_block_editor_assets', 'twentyeleven_block_editor_styles' );
 323  
 324  if ( ! function_exists( 'twentyeleven_header_style' ) ) :
 325      /**
 326       * Styles the header image and text displayed on the blog.
 327       *
 328       * @since Twenty Eleven 1.0
 329       */
 330  	function twentyeleven_header_style() {
 331          $text_color = get_header_textcolor();
 332  
 333          // If no custom options for text are set, let's bail.
 334          if ( HEADER_TEXTCOLOR === $text_color ) {
 335              return;
 336          }
 337  
 338          // If we get this far, we have custom styles. Let's do this.
 339          ?>
 340          <style id="twentyeleven-header-css">
 341          <?php
 342          // Has the text been hidden?
 343          if ( 'blank' === $text_color ) :
 344              ?>
 345          #site-title,
 346          #site-description {
 347              position: absolute;
 348              clip-path: inset(50%);
 349          }
 350              <?php
 351              // If the user has set a custom color for the text, use that.
 352          else :
 353              ?>
 354          #site-title a,
 355          #site-description {
 356              color: #<?php echo $text_color; ?>;
 357          }
 358      <?php endif; ?>
 359      </style>
 360          <?php
 361      }
 362  endif; // twentyeleven_header_style()
 363  
 364  if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) :
 365      /**
 366       * Styles the header image displayed on the Appearance > Header admin panel.
 367       *
 368       * Referenced via add_theme_support('custom-header') in twentyeleven_setup().
 369       *
 370       * @since Twenty Eleven 1.0
 371       */
 372  	function twentyeleven_admin_header_style() {
 373          ?>
 374      <style id="twentyeleven-admin-header-css">
 375      .appearance_page_custom-header #headimg {
 376          border: none;
 377      }
 378      #headimg h1,
 379      #desc {
 380          font-family: "Helvetica Neue", Arial, Helvetica, "Nimbus Sans L", sans-serif;
 381      }
 382      #headimg h1 {
 383          margin: 0;
 384      }
 385      #headimg h1 a {
 386          font-size: 32px;
 387          line-height: 36px;
 388          text-decoration: none;
 389      }
 390      #desc {
 391          font-size: 14px;
 392          line-height: 23px;
 393          padding: 0 0 3em;
 394      }
 395          <?php
 396          // If the user has set a custom color for the text, use that.
 397          if ( get_header_textcolor() !== HEADER_TEXTCOLOR ) :
 398              ?>
 399      #site-title a,
 400      #site-description {
 401          color: #<?php echo get_header_textcolor(); ?>;
 402      }
 403      <?php endif; ?>
 404      #headimg img {
 405          max-width: 1000px;
 406          height: auto;
 407          width: 100%;
 408      }
 409      </style>
 410          <?php
 411      }
 412  endif; // twentyeleven_admin_header_style()
 413  
 414  if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) :
 415      /**
 416       * Displays custom header image markup on the Appearance > Header admin panel.
 417       *
 418       * Referenced via add_theme_support('custom-header') in twentyeleven_setup().
 419       *
 420       * @since Twenty Eleven 1.0
 421       */
 422  	function twentyeleven_admin_header_image() {
 423  
 424          ?>
 425          <div id="headimg">
 426              <?php
 427              $color = get_header_textcolor();
 428              $image = get_header_image();
 429              $style = 'display: none;';
 430              if ( $color && 'blank' !== $color ) {
 431                  $style = 'color: #' . $color . ';';
 432              }
 433              ?>
 434              <h1 class="displaying-header-text"><a id="name" style="<?php echo esc_attr( $style ); ?>" onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1>
 435          <div id="desc" class="displaying-header-text" style="<?php echo esc_attr( $style ); ?>"><?php bloginfo( 'description' ); ?></div>
 436          <?php if ( $image ) : ?>
 437              <img src="<?php echo esc_url( $image ); ?>" alt="" />
 438          <?php endif; ?>
 439          </div>
 440          <?php
 441      }
 442  endif; // twentyeleven_admin_header_image()
 443  
 444  
 445  if ( ! function_exists( 'twentyeleven_header_image' ) ) :
 446      /**
 447       * Displays custom header image markup.
 448       *
 449       * @since Twenty Eleven 4.5
 450       */
 451  	function twentyeleven_header_image() {
 452          $attrs = array(
 453              'alt' => get_bloginfo( 'name', 'display' ),
 454          );
 455  
 456          // Compatibility with versions of WordPress prior to 3.4.
 457          if ( function_exists( 'get_custom_header' ) ) {
 458              $custom_header   = get_custom_header();
 459              $attrs['width']  = $custom_header->width;
 460              $attrs['height'] = $custom_header->height;
 461          } else {
 462              $attrs['width']  = HEADER_IMAGE_WIDTH;
 463              $attrs['height'] = HEADER_IMAGE_HEIGHT;
 464          }
 465  
 466          if ( function_exists( 'the_header_image_tag' ) ) {
 467              the_header_image_tag( $attrs );
 468              return;
 469          }
 470  
 471          ?>
 472          <img src="<?php header_image(); ?>" width="<?php echo esc_attr( $attrs['width'] ); ?>" height="<?php echo esc_attr( $attrs['height'] ); ?>" alt="<?php echo esc_attr( $attrs['alt'] ); ?>" />
 473          <?php
 474      }
 475  endif; // twentyeleven_header_image()
 476  
 477  /**
 478   * Sets the post excerpt length to 40 words.
 479   *
 480   * To override this length in a child theme, remove
 481   * the filter and add your own function tied to
 482   * the excerpt_length filter hook.
 483   *
 484   * @since Twenty Eleven 1.0
 485   *
 486   * @param int $length The number of excerpt characters.
 487   * @return int The filtered number of characters.
 488   */
 489  function twentyeleven_excerpt_length( $length ) {
 490      return 40;
 491  }
 492  add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
 493  
 494  if ( ! function_exists( 'twentyeleven_continue_reading_link' ) ) :
 495      /**
 496       * Returns a "Continue Reading" link for excerpts.
 497       *
 498       * @since Twenty Eleven 1.0
 499       *
 500       * @return string The "Continue Reading" HTML link.
 501       */
 502  	function twentyeleven_continue_reading_link() {
 503          return ' <a href="' . esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) . '</a>';
 504      }
 505  endif; // twentyeleven_continue_reading_link()
 506  
 507  /**
 508   * Replaces "[...]" in the Read More link with an ellipsis.
 509   *
 510   * The "[...]" is appended to automatically generated excerpts.
 511   *
 512   * To override this in a child theme, remove the filter and add your own
 513   * function tied to the excerpt_more filter hook.
 514   *
 515   * @since Twenty Eleven 1.0
 516   *
 517   * @param string $more The Read More text.
 518   * @return string The filtered Read More text.
 519   */
 520  function twentyeleven_auto_excerpt_more( $more ) {
 521      if ( ! is_admin() ) {
 522          return ' &hellip;' . twentyeleven_continue_reading_link();
 523      }
 524      return $more;
 525  }
 526  add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );
 527  
 528  /**
 529   * Adds a pretty "Continue Reading" link to custom post excerpts.
 530   *
 531   * To override this link in a child theme, remove the filter and add your own
 532   * function tied to the get_the_excerpt filter hook.
 533   *
 534   * @since Twenty Eleven 1.0
 535   *
 536   * @param string $output The "Continue Reading" link.
 537   * @return string The filtered "Continue Reading" link.
 538   */
 539  function twentyeleven_custom_excerpt_more( $output ) {
 540      if ( has_excerpt() && ! is_attachment() && ! is_admin() ) {
 541          $output .= twentyeleven_continue_reading_link();
 542      }
 543      return $output;
 544  }
 545  add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
 546  
 547  /**
 548   * Shows a home link for the wp_nav_menu() fallback, wp_page_menu().
 549   *
 550   * @since Twenty Eleven 1.0
 551   *
 552   * @param array $args The page menu arguments. @see wp_page_menu()
 553   * @return array The filtered page menu arguments.
 554   */
 555  function twentyeleven_page_menu_args( $args ) {
 556      if ( ! isset( $args['show_home'] ) ) {
 557          $args['show_home'] = true;
 558      }
 559      return $args;
 560  }
 561  add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' );
 562  
 563  /**
 564   * Registers sidebars and widgetized areas.
 565   *
 566   * Also register the default Ephemera widget.
 567   *
 568   * @since Twenty Eleven 1.0
 569   */
 570  function twentyeleven_widgets_init() {
 571  
 572      register_widget( 'Twenty_Eleven_Ephemera_Widget' );
 573  
 574      register_sidebar(
 575          array(
 576              'name'          => __( 'Main Sidebar', 'twentyeleven' ),
 577              'id'            => 'sidebar-1',
 578              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 579              'after_widget'  => '</aside>',
 580              'before_title'  => '<h3 class="widget-title">',
 581              'after_title'   => '</h3>',
 582          )
 583      );
 584  
 585      register_sidebar(
 586          array(
 587              'name'          => __( 'Showcase Sidebar', 'twentyeleven' ),
 588              'id'            => 'sidebar-2',
 589              'description'   => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ),
 590              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 591              'after_widget'  => '</aside>',
 592              'before_title'  => '<h3 class="widget-title">',
 593              'after_title'   => '</h3>',
 594          )
 595      );
 596  
 597      register_sidebar(
 598          array(
 599              'name'          => __( 'Footer Area One', 'twentyeleven' ),
 600              'id'            => 'sidebar-3',
 601              'description'   => __( 'An optional widget area for your site footer', 'twentyeleven' ),
 602              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 603              'after_widget'  => '</aside>',
 604              'before_title'  => '<h3 class="widget-title">',
 605              'after_title'   => '</h3>',
 606          )
 607      );
 608  
 609      register_sidebar(
 610          array(
 611              'name'          => __( 'Footer Area Two', 'twentyeleven' ),
 612              'id'            => 'sidebar-4',
 613              'description'   => __( 'An optional widget area for your site footer', 'twentyeleven' ),
 614              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 615              'after_widget'  => '</aside>',
 616              'before_title'  => '<h3 class="widget-title">',
 617              'after_title'   => '</h3>',
 618          )
 619      );
 620  
 621      register_sidebar(
 622          array(
 623              'name'          => __( 'Footer Area Three', 'twentyeleven' ),
 624              'id'            => 'sidebar-5',
 625              'description'   => __( 'An optional widget area for your site footer', 'twentyeleven' ),
 626              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 627              'after_widget'  => '</aside>',
 628              'before_title'  => '<h3 class="widget-title">',
 629              'after_title'   => '</h3>',
 630          )
 631      );
 632  }
 633  add_action( 'widgets_init', 'twentyeleven_widgets_init' );
 634  
 635  if ( ! function_exists( 'twentyeleven_content_nav' ) ) :
 636      /**
 637       * Displays navigation to next/previous pages when applicable.
 638       *
 639       * @since Twenty Eleven 1.0
 640       *
 641       * @global WP_Query $wp_query WordPress Query object.
 642       *
 643       * @param string $html_id The HTML id attribute.
 644       */
 645  	function twentyeleven_content_nav( $html_id ) {
 646          global $wp_query;
 647  
 648          if ( $wp_query->max_num_pages > 1 ) :
 649              $order   = get_query_var( 'order', 'DESC' );
 650              $is_desc = ( 'DESC' === $order );
 651  
 652              $new_posts_text = __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyeleven' );
 653              $old_posts_text = __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyeleven' );
 654  
 655              $prev_link = $is_desc ? get_next_posts_link( $old_posts_text ) : get_previous_posts_link( $old_posts_text );
 656              $next_link = $is_desc ? get_previous_posts_link( $new_posts_text ) : get_next_posts_link( $new_posts_text );
 657              ?>
 658              <nav id="<?php echo esc_attr( $html_id ); ?>">
 659                  <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
 660                  <?php if ( $prev_link ) : ?>
 661                      <div class="nav-previous"><?php echo $prev_link; ?></div>
 662                  <?php endif; ?>
 663  
 664                  <?php if ( $next_link ) : ?>
 665                      <div class="nav-next"><?php echo $next_link; ?></div>
 666                  <?php endif; ?>
 667              </nav><!-- #<?php echo esc_attr( $html_id ); ?> -->
 668              <?php
 669          endif;
 670      }
 671  endif; // twentyeleven_content_nav()
 672  
 673  /**
 674   * Returns the first link from the post content. If none found, the
 675   * post permalink is used as a fallback.
 676   *
 677   * @since Twenty Eleven 1.0
 678   *
 679   * @uses get_url_in_content() to get the first URL from the post content.
 680   *
 681   * @return string The first link.
 682   */
 683  function twentyeleven_get_first_url() {
 684      $content = get_the_content();
 685      $has_url = function_exists( 'get_url_in_content' ) ? get_url_in_content( $content ) : false;
 686  
 687      if ( ! $has_url ) {
 688          $has_url = twentyeleven_url_grabber();
 689      }
 690  
 691      /** This filter is documented in wp-includes/link-template.php */
 692      return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
 693  }
 694  
 695  /**
 696   * Returns the URL for the first link found in the post content.
 697   *
 698   * @since Twenty Eleven 1.0
 699   *
 700   * @return string|bool URL or false when no link is present.
 701   */
 702  function twentyeleven_url_grabber() {
 703      if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) {
 704          return false;
 705      }
 706  
 707      return esc_url_raw( $matches[1] );
 708  }
 709  
 710  /**
 711   * Counts the number of footer sidebars to enable dynamic classes for the footer.
 712   *
 713   * @since Twenty Eleven 1.0
 714   */
 715  function twentyeleven_footer_sidebar_class() {
 716      $count = 0;
 717  
 718      if ( is_active_sidebar( 'sidebar-3' ) ) {
 719          ++$count;
 720      }
 721  
 722      if ( is_active_sidebar( 'sidebar-4' ) ) {
 723          ++$count;
 724      }
 725  
 726      if ( is_active_sidebar( 'sidebar-5' ) ) {
 727          ++$count;
 728      }
 729  
 730      $class = '';
 731  
 732      switch ( $count ) {
 733          case '1':
 734              $class = 'one';
 735              break;
 736          case '2':
 737              $class = 'two';
 738              break;
 739          case '3':
 740              $class = 'three';
 741              break;
 742      }
 743  
 744      if ( $class ) {
 745          echo 'class="' . esc_attr( $class ) . '"';
 746      }
 747  }
 748  
 749  if ( ! function_exists( 'twentyeleven_comment' ) ) :
 750      /**
 751       * Template for comments and pingbacks.
 752       *
 753       * To override this walker in a child theme without modifying the comments template
 754       * simply create your own twentyeleven_comment(), and that function will be used instead.
 755       *
 756       * Used as a callback by wp_list_comments() for displaying the comments.
 757       *
 758       * @since Twenty Eleven 1.0
 759       *
 760       * @global WP_Comment $comment Global comment object.
 761       *
 762       * @param WP_Comment $comment The comment object.
 763       * @param array      $args    An array of comment arguments. @see get_comment_reply_link()
 764       * @param int        $depth   The depth of the comment.
 765       */
 766  	function twentyeleven_comment( $comment, $args, $depth ) {
 767          $GLOBALS['comment'] = $comment;
 768          switch ( $comment->comment_type ) :
 769              case 'pingback':
 770              case 'trackback':
 771                  ?>
 772          <li class="post pingback">
 773          <p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p>
 774                  <?php
 775                  break;
 776              default:
 777                  ?>
 778          <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
 779          <article id="comment-<?php comment_ID(); ?>" class="comment">
 780              <footer class="comment-meta">
 781                  <div class="comment-author vcard">
 782                      <?php
 783                      $avatar_size = 68;
 784  
 785                      if ( '0' !== $comment->comment_parent ) {
 786                          $avatar_size = 39;
 787                      }
 788  
 789                      echo get_avatar( $comment, $avatar_size );
 790  
 791                      printf(
 792                          /* translators: 1: Comment author, 2: Date and time. */
 793                          __( '%1$s on %2$s <span class="says">said:</span>', 'twentyeleven' ),
 794                          sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
 795                          sprintf(
 796                              '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
 797                              esc_url( get_comment_link( $comment->comment_ID ) ),
 798                              get_comment_time( 'c' ),
 799                              /* translators: 1: Date, 2: Time. */
 800                              sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time() )
 801                          )
 802                      );
 803                      ?>
 804  
 805                      <?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?>
 806                      </div><!-- .comment-author .vcard -->
 807  
 808                      <?php
 809                      $commenter = wp_get_current_commenter();
 810                      if ( $commenter['comment_author_email'] ) {
 811                          $moderation_note = __( 'Your comment is awaiting moderation.', 'twentyeleven' );
 812                      } else {
 813                          $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.', 'twentyeleven' );
 814                      }
 815                      ?>
 816  
 817                      <?php if ( '0' === $comment->comment_approved ) : ?>
 818                      <em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em>
 819                      <br />
 820                      <?php endif; ?>
 821  
 822                  </footer>
 823  
 824                  <div class="comment-content"><?php comment_text(); ?></div>
 825  
 826                  <div class="reply">
 827                      <?php
 828                      comment_reply_link(
 829                          array_merge(
 830                              $args,
 831                              array(
 832                                  'reply_text' => __( 'Reply <span>&darr;</span>', 'twentyeleven' ),
 833                                  'depth'      => $depth,
 834                                  'max_depth'  => $args['max_depth'],
 835                              )
 836                          )
 837                      );
 838                      ?>
 839                  </div><!-- .reply -->
 840              </article><!-- #comment-## -->
 841  
 842                  <?php
 843                  break;
 844          endswitch;
 845      }
 846  endif; // twentyeleven_comment()
 847  
 848  if ( ! function_exists( 'twentyeleven_posted_on' ) ) :
 849      /**
 850       * Prints HTML with meta information for the current post-date/time and author.
 851       *
 852       * Create your own twentyeleven_posted_on to override in a child theme
 853       *
 854       * @since Twenty Eleven 1.0
 855       */
 856  	function twentyeleven_posted_on() {
 857          printf(
 858              /* translators: 1: The permalink, 2: Time, 3: Date and time, 4: Date and time, 5: Author posts, 6: Author post link text, 7: Author display name. */
 859              __( '<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ),
 860              esc_url( get_permalink() ),
 861              esc_attr( get_the_time() ),
 862              esc_attr( get_the_date( 'c' ) ),
 863              esc_html( get_the_date() ),
 864              esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
 865              /* translators: %s: Author display name. */
 866              esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ),
 867              get_the_author()
 868          );
 869      }
 870  endif;
 871  
 872  /**
 873   * Adds two classes to the array of body classes.
 874   *
 875   * The first is if the site has only had one author with published posts.
 876   * The second is if a singular post being displayed
 877   *
 878   * @since Twenty Eleven 1.0
 879   *
 880   * @param array $classes Existing body classes.
 881   * @return array The filtered array of body classes.
 882   */
 883  function twentyeleven_body_classes( $classes ) {
 884  
 885      if ( function_exists( 'is_multi_author' ) && ! is_multi_author() ) {
 886          $classes[] = 'single-author';
 887      }
 888  
 889      if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) ) {
 890          $classes[] = 'singular';
 891      }
 892  
 893      return $classes;
 894  }
 895  add_filter( 'body_class', 'twentyeleven_body_classes' );
 896  
 897  /**
 898   * Retrieves the IDs for images in a gallery.
 899   *
 900   * @uses get_post_galleries() First, if available. Falls back to shortcode parsing,
 901   *                            then as last option uses a get_posts() call.
 902   *
 903   * @since Twenty Eleven 1.6
 904   *
 905   * @return array List of image IDs from the post gallery.
 906   */
 907  function twentyeleven_get_gallery_images() {
 908      $images = array();
 909  
 910      if ( function_exists( 'get_post_galleries' ) ) {
 911          $galleries = get_post_galleries( get_the_ID(), false );
 912          if ( isset( $galleries[0]['ids'] ) ) {
 913              $images = explode( ',', $galleries[0]['ids'] );
 914          }
 915      } else {
 916          $pattern = get_shortcode_regex();
 917          preg_match( "/$pattern/s", get_the_content(), $match );
 918          $atts = shortcode_parse_atts( $match[3] );
 919          if ( isset( $atts['ids'] ) ) {
 920              $images = explode( ',', $atts['ids'] );
 921          }
 922      }
 923  
 924      if ( ! $images ) {
 925          $images = get_posts(
 926              array(
 927                  'fields'         => 'ids',
 928                  'numberposts'    => 999,
 929                  'order'          => 'ASC',
 930                  'orderby'        => 'menu_order',
 931                  'post_mime_type' => 'image',
 932                  'post_parent'    => get_the_ID(),
 933                  'post_type'      => 'attachment',
 934              )
 935          );
 936      }
 937  
 938      return $images;
 939  }
 940  
 941  /**
 942   * Modifies tag cloud widget arguments to display all tags in the same font size
 943   * and use list format for better accessibility.
 944   *
 945   * @since Twenty Eleven 2.7
 946   *
 947   * @param array $args Arguments for tag cloud widget.
 948   * @return array The filtered arguments for tag cloud widget.
 949   */
 950  function twentyeleven_widget_tag_cloud_args( $args ) {
 951      $args['largest']  = 22;
 952      $args['smallest'] = 8;
 953      $args['unit']     = 'pt';
 954      $args['format']   = 'list';
 955  
 956      return $args;
 957  }
 958  add_filter( 'widget_tag_cloud_args', 'twentyeleven_widget_tag_cloud_args' );
 959  
 960  if ( ! function_exists( 'wp_body_open' ) ) :
 961      /**
 962       * Fires the wp_body_open action.
 963       *
 964       * Added for backward compatibility to support pre-5.2.0 WordPress versions.
 965       *
 966       * @since Twenty Eleven 3.3
 967       */
 968  	function wp_body_open() {
 969          /**
 970           * Triggered after the opening <body> tag.
 971           *
 972           * @since Twenty Eleven 3.3
 973           */
 974          do_action( 'wp_body_open' );
 975      }
 976  endif;
 977  
 978  /**
 979   * Includes a skip to content link at the top of the page so that users can bypass the menu.
 980   *
 981   * @since Twenty Eleven 3.4
 982   */
 983  function twentyeleven_skip_link() {
 984      echo '<div class="skip-link"><a class="assistive-text" href="#content">' . esc_html__( 'Skip to primary content', 'twentyeleven' ) . '</a></div>';
 985      if ( ! is_singular() ) {
 986          echo '<div class="skip-link"><a class="assistive-text" href="#secondary">' . esc_html__( 'Skip to secondary content', 'twentyeleven' ) . '</a></div>';
 987      }
 988  }
 989  add_action( 'wp_body_open', 'twentyeleven_skip_link', 5 );
 990  
 991  if ( ! function_exists( 'wp_get_list_item_separator' ) ) :
 992      /**
 993       * Retrieves the list item separator based on the locale.
 994       *
 995       * Added for backward compatibility to support pre-6.0.0 WordPress versions.
 996       *
 997       * @since Twenty Eleven 4.1
 998       *
 999       * @return string Locale-specific list item separator.
1000       */
1001  	function wp_get_list_item_separator() {
1002          /* translators: Used between list items, there is a space after the comma. */
1003          return __( ', ', 'twentyeleven' );
1004      }
1005  endif;


Generated : Thu Jun 25 08:20:12 2026 Cross-referenced by PHPXref