[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Twenty Thirteen 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, @link https://developer.wordpress.org/plugins/
  21   *
  22   * @package WordPress
  23   * @subpackage Twenty_Thirteen
  24   * @since Twenty Thirteen 1.0
  25   */
  26  
  27  /*
  28   * Set up the content width value based on the theme's design.
  29   *
  30   * @see twentythirteen_content_width() for template-specific adjustments.
  31   */
  32  if ( ! isset( $content_width ) ) {
  33      $content_width = 604;
  34  }
  35  
  36  /**
  37   * Add support for a custom header image.
  38   */
  39  require get_template_directory() . '/inc/custom-header.php';
  40  
  41  /**
  42   * Twenty Thirteen only works in WordPress 3.6 or later.
  43   */
  44  if ( version_compare( $GLOBALS['wp_version'], '3.6-alpha', '<' ) ) {
  45      require get_template_directory() . '/inc/back-compat.php';
  46  }
  47  
  48  /**
  49   * Twenty Thirteen setup.
  50   *
  51   * Sets up theme defaults and registers the various WordPress features that
  52   * Twenty Thirteen supports.
  53   *
  54   * @uses load_theme_textdomain() For translation/localization support.
  55   * @uses add_editor_style() To add Visual Editor stylesheets.
  56   * @uses add_theme_support() To add support for automatic feed links, post
  57   * formats, and post thumbnails.
  58   * @uses register_nav_menu() To add support for a navigation menu.
  59   * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  60   *
  61   * @since Twenty Thirteen 1.0
  62   */
  63  function twentythirteen_setup() {
  64      /*
  65       * Makes Twenty Thirteen available for translation.
  66       *
  67       * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentythirteen
  68       * If you're building a theme based on Twenty Thirteen, use a find and
  69       * replace to change 'twentythirteen' to the name of your theme in all
  70       * template files.
  71       */
  72      load_theme_textdomain( 'twentythirteen' );
  73  
  74      /*
  75       * This theme styles the visual editor to resemble the theme style,
  76       * specifically font, colors, icons, and column width.
  77       */
  78      add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', twentythirteen_fonts_url() ) );
  79  
  80      // Load regular editor styles into the new block-based editor.
  81      add_theme_support( 'editor-styles' );
  82  
  83      // Load default block styles.
  84      add_theme_support( 'wp-block-styles' );
  85  
  86      // Add support for full and wide align images.
  87      add_theme_support( 'align-wide' );
  88  
  89      // Add support for responsive embeds.
  90      add_theme_support( 'responsive-embeds' );
  91  
  92      // Add support for custom color scheme.
  93      add_theme_support(
  94          'editor-color-palette',
  95          array(
  96              array(
  97                  'name'  => __( 'Dark Gray', 'twentythirteen' ),
  98                  'slug'  => 'dark-gray',
  99                  'color' => '#141412',
 100              ),
 101              array(
 102                  'name'  => __( 'Red', 'twentythirteen' ),
 103                  'slug'  => 'red',
 104                  'color' => '#bc360a',
 105              ),
 106              array(
 107                  'name'  => __( 'Medium Orange', 'twentythirteen' ),
 108                  'slug'  => 'medium-orange',
 109                  'color' => '#db572f',
 110              ),
 111              array(
 112                  'name'  => __( 'Light Orange', 'twentythirteen' ),
 113                  'slug'  => 'light-orange',
 114                  'color' => '#ea9629',
 115              ),
 116              array(
 117                  'name'  => __( 'Yellow', 'twentythirteen' ),
 118                  'slug'  => 'yellow',
 119                  'color' => '#fbca3c',
 120              ),
 121              array(
 122                  'name'  => __( 'White', 'twentythirteen' ),
 123                  'slug'  => 'white',
 124                  'color' => '#fff',
 125              ),
 126              array(
 127                  'name'  => __( 'Dark Brown', 'twentythirteen' ),
 128                  'slug'  => 'dark-brown',
 129                  'color' => '#220e10',
 130              ),
 131              array(
 132                  'name'  => __( 'Medium Brown', 'twentythirteen' ),
 133                  'slug'  => 'medium-brown',
 134                  'color' => '#722d19',
 135              ),
 136              array(
 137                  'name'  => __( 'Light Brown', 'twentythirteen' ),
 138                  'slug'  => 'light-brown',
 139                  'color' => '#eadaa6',
 140              ),
 141              array(
 142                  'name'  => __( 'Beige', 'twentythirteen' ),
 143                  'slug'  => 'beige',
 144                  'color' => '#e8e5ce',
 145              ),
 146              array(
 147                  'name'  => __( 'Off-white', 'twentythirteen' ),
 148                  'slug'  => 'off-white',
 149                  'color' => '#f7f5e7',
 150              ),
 151          )
 152      );
 153  
 154      // Adds RSS feed links to <head> for posts and comments.
 155      add_theme_support( 'automatic-feed-links' );
 156  
 157      /*
 158       * Switches default core markup for search form, comment form,
 159       * and comments to output valid HTML5.
 160       */
 161      add_theme_support(
 162          'html5',
 163          array(
 164              'search-form',
 165              'comment-form',
 166              'comment-list',
 167              'gallery',
 168              'caption',
 169              'script',
 170              'style',
 171          )
 172      );
 173  
 174      /*
 175       * This theme supports all available post formats by default.
 176       * See https://wordpress.org/support/article/post-formats/
 177       */
 178      add_theme_support(
 179          'post-formats',
 180          array(
 181              'aside',
 182              'audio',
 183              'chat',
 184              'gallery',
 185              'image',
 186              'link',
 187              'quote',
 188              'status',
 189              'video',
 190          )
 191      );
 192  
 193      // This theme uses wp_nav_menu() in one location.
 194      register_nav_menu( 'primary', __( 'Navigation Menu', 'twentythirteen' ) );
 195  
 196      /*
 197       * This theme uses a custom image size for featured images, displayed on
 198       * "standard" posts and pages.
 199       */
 200      add_theme_support( 'post-thumbnails' );
 201      set_post_thumbnail_size( 604, 270, true );
 202  
 203      // This theme uses its own gallery styles.
 204      add_filter( 'use_default_gallery_style', '__return_false' );
 205  
 206      // Indicate widget sidebars can use selective refresh in the Customizer.
 207      add_theme_support( 'customize-selective-refresh-widgets' );
 208  }
 209  add_action( 'after_setup_theme', 'twentythirteen_setup' );
 210  
 211  /**
 212   * Return the Google font stylesheet URL, if available.
 213   *
 214   * The use of Source Sans Pro and Bitter by default is localized. For languages
 215   * that use characters not supported by the font, the font can be disabled.
 216   *
 217   * @since Twenty Thirteen 1.0
 218   *
 219   * @return string Font stylesheet or empty string if disabled.
 220   */
 221  function twentythirteen_fonts_url() {
 222      $fonts_url = '';
 223  
 224      /*
 225       * translators: If there are characters in your language that are not supported
 226       * by Source Sans Pro, translate this to 'off'. Do not translate into your own language.
 227       */
 228      $source_sans_pro = _x( 'on', 'Source Sans Pro font: on or off', 'twentythirteen' );
 229  
 230      /*
 231       * translators: If there are characters in your language that are not supported
 232       * by Bitter, translate this to 'off'. Do not translate into your own language.
 233       */
 234      $bitter = _x( 'on', 'Bitter font: on or off', 'twentythirteen' );
 235  
 236      if ( 'off' !== $source_sans_pro || 'off' !== $bitter ) {
 237          $font_families = array();
 238  
 239          if ( 'off' !== $source_sans_pro ) {
 240              $font_families[] = 'Source Sans Pro:300,400,700,300italic,400italic,700italic';
 241          }
 242  
 243          if ( 'off' !== $bitter ) {
 244              $font_families[] = 'Bitter:400,700';
 245          }
 246  
 247          $query_args = array(
 248              'family'  => urlencode( implode( '|', $font_families ) ),
 249              'subset'  => urlencode( 'latin,latin-ext' ),
 250              'display' => urlencode( 'fallback' ),
 251          );
 252          $fonts_url  = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
 253      }
 254  
 255      return $fonts_url;
 256  }
 257  
 258  /**
 259   * Enqueue scripts and styles for the front end.
 260   *
 261   * @since Twenty Thirteen 1.0
 262   */
 263  function twentythirteen_scripts_styles() {
 264      /*
 265       * Adds JavaScript to pages with the comment form to support
 266       * sites with threaded comments (when in use).
 267       */
 268      if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
 269          wp_enqueue_script( 'comment-reply' );
 270      }
 271  
 272      // Adds Masonry to handle vertical alignment of footer widgets.
 273      if ( is_active_sidebar( 'sidebar-1' ) ) {
 274          wp_enqueue_script( 'jquery-masonry' );
 275      }
 276  
 277      // Loads JavaScript file with functionality specific to Twenty Thirteen.
 278      wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20171218', true );
 279  
 280      // Add Source Sans Pro and Bitter fonts, used in the main stylesheet.
 281      wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null );
 282  
 283      // Add Genericons font, used in the main stylesheet.
 284      wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.0.3' );
 285  
 286      // Loads our main stylesheet.
 287      wp_enqueue_style( 'twentythirteen-style', get_stylesheet_uri(), array(), '20190507' );
 288  
 289      // Theme block stylesheet.
 290      wp_enqueue_style( 'twentythirteen-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'twentythirteen-style' ), '20190102' );
 291  
 292      // Loads the Internet Explorer specific stylesheet.
 293      wp_enqueue_style( 'twentythirteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentythirteen-style' ), '20150214' );
 294      wp_style_add_data( 'twentythirteen-ie', 'conditional', 'lt IE 9' );
 295  }
 296  add_action( 'wp_enqueue_scripts', 'twentythirteen_scripts_styles' );
 297  
 298  /**
 299   * Add preconnect for Google Fonts.
 300   *
 301   * @since Twenty Thirteen 2.1
 302   *
 303   * @param array   $urls          URLs to print for resource hints.
 304   * @param string  $relation_type The relation type the URLs are printed.
 305   * @return array URLs to print for resource hints.
 306   */
 307  function twentythirteen_resource_hints( $urls, $relation_type ) {
 308      if ( wp_style_is( 'twentythirteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
 309          if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
 310              $urls[] = array(
 311                  'href' => 'https://fonts.gstatic.com',
 312                  'crossorigin',
 313              );
 314          } else {
 315              $urls[] = 'https://fonts.gstatic.com';
 316          }
 317      }
 318  
 319      return $urls;
 320  }
 321  add_filter( 'wp_resource_hints', 'twentythirteen_resource_hints', 10, 2 );
 322  
 323  /**
 324   * Enqueue styles for the block-based editor.
 325   *
 326   * @since Twenty Thirteen 2.5
 327   */
 328  function twentythirteen_block_editor_styles() {
 329      // Block styles.
 330      wp_enqueue_style( 'twentythirteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20190102' );
 331      // Add custom fonts.
 332      wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null );
 333  }
 334  add_action( 'enqueue_block_editor_assets', 'twentythirteen_block_editor_styles' );
 335  
 336  /**
 337   * Filter the page title.
 338   *
 339   * Creates a nicely formatted and more specific title element text for output
 340   * in head of document, based on current view.
 341   *
 342   * @since Twenty Thirteen 1.0
 343   *
 344   * @param string $title Default title text for current view.
 345   * @param string $sep   Optional separator.
 346   * @return string The filtered title.
 347   */
 348  function twentythirteen_wp_title( $title, $sep ) {
 349      global $paged, $page;
 350  
 351      if ( is_feed() ) {
 352          return $title;
 353      }
 354  
 355      // Add the site name.
 356      $title .= get_bloginfo( 'name', 'display' );
 357  
 358      // Add the site description for the home/front page.
 359      $site_description = get_bloginfo( 'description', 'display' );
 360      if ( $site_description && ( is_home() || is_front_page() ) ) {
 361          $title = "$title $sep $site_description";
 362      }
 363  
 364      // Add a page number if necessary.
 365      if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
 366          /* translators: %s: Page number. */
 367          $title = "$title $sep " . sprintf( __( 'Page %s', 'twentythirteen' ), max( $paged, $page ) );
 368      }
 369  
 370      return $title;
 371  }
 372  add_filter( 'wp_title', 'twentythirteen_wp_title', 10, 2 );
 373  
 374  /**
 375   * Register two widget areas.
 376   *
 377   * @since Twenty Thirteen 1.0
 378   */
 379  function twentythirteen_widgets_init() {
 380      register_sidebar(
 381          array(
 382              'name'          => __( 'Main Widget Area', 'twentythirteen' ),
 383              'id'            => 'sidebar-1',
 384              'description'   => __( 'Appears in the footer section of the site.', 'twentythirteen' ),
 385              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 386              'after_widget'  => '</aside>',
 387              'before_title'  => '<h3 class="widget-title">',
 388              'after_title'   => '</h3>',
 389          )
 390      );
 391  
 392      register_sidebar(
 393          array(
 394              'name'          => __( 'Secondary Widget Area', 'twentythirteen' ),
 395              'id'            => 'sidebar-2',
 396              'description'   => __( 'Appears on posts and pages in the sidebar.', 'twentythirteen' ),
 397              'before_widget' => '<aside id="%1$s" class="widget %2$s">',
 398              'after_widget'  => '</aside>',
 399              'before_title'  => '<h3 class="widget-title">',
 400              'after_title'   => '</h3>',
 401          )
 402      );
 403  }
 404  add_action( 'widgets_init', 'twentythirteen_widgets_init' );
 405  
 406  if ( ! function_exists( 'twentythirteen_paging_nav' ) ) :
 407      /**
 408       * Display navigation to next/previous set of posts when applicable.
 409       *
 410       * @since Twenty Thirteen 1.0
 411       */
 412  	function twentythirteen_paging_nav() {
 413          global $wp_query;
 414  
 415          // Don't print empty markup if there's only one page.
 416          if ( $wp_query->max_num_pages < 2 ) {
 417              return;
 418          }
 419          ?>
 420          <nav class="navigation paging-navigation" role="navigation">
 421          <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1>
 422          <div class="nav-links">
 423  
 424              <?php if ( get_next_posts_link() ) : ?>
 425              <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentythirteen' ) ); ?></div>
 426              <?php endif; ?>
 427  
 428              <?php if ( get_previous_posts_link() ) : ?>
 429              <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentythirteen' ) ); ?></div>
 430              <?php endif; ?>
 431  
 432          </div><!-- .nav-links -->
 433      </nav><!-- .navigation -->
 434          <?php
 435      }
 436  endif;
 437  
 438  if ( ! function_exists( 'twentythirteen_post_nav' ) ) :
 439      /**
 440       * Display navigation to next/previous post when applicable.
 441       *
 442       * @since Twenty Thirteen 1.0
 443       */
 444  	function twentythirteen_post_nav() {
 445          global $post;
 446  
 447          // Don't print empty markup if there's nowhere to navigate.
 448          $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
 449          $next     = get_adjacent_post( false, '', false );
 450  
 451          if ( ! $next && ! $previous ) {
 452              return;
 453          }
 454          ?>
 455          <nav class="navigation post-navigation" role="navigation">
 456          <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentythirteen' ); ?></h1>
 457          <div class="nav-links">
 458  
 459              <?php previous_post_link( '%link', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'twentythirteen' ) ); ?>
 460              <?php next_post_link( '%link', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'twentythirteen' ) ); ?>
 461  
 462          </div><!-- .nav-links -->
 463      </nav><!-- .navigation -->
 464          <?php
 465      }
 466  endif;
 467  
 468  if ( ! function_exists( 'twentythirteen_entry_meta' ) ) :
 469      /**
 470       * Print HTML with meta information for current post: categories, tags, permalink, author, and date.
 471       *
 472       * Create your own twentythirteen_entry_meta() to override in a child theme.
 473       *
 474       * @since Twenty Thirteen 1.0
 475       */
 476  	function twentythirteen_entry_meta() {
 477          if ( is_sticky() && is_home() && ! is_paged() ) {
 478              echo '<span class="featured-post">' . esc_html__( 'Sticky', 'twentythirteen' ) . '</span>';
 479          }
 480  
 481          if ( ! has_post_format( 'link' ) && 'post' == get_post_type() ) {
 482              twentythirteen_entry_date();
 483          }
 484  
 485          /* translators: Used between list items, there is a space after the comma. */
 486          $categories_list = get_the_category_list( __( ', ', 'twentythirteen' ) );
 487          if ( $categories_list ) {
 488              echo '<span class="categories-links">' . $categories_list . '</span>';
 489          }
 490  
 491          /* translators: Used between list items, there is a space after the comma. */
 492          $tag_list = get_the_tag_list( '', __( ', ', 'twentythirteen' ) );
 493          if ( $tag_list ) {
 494              echo '<span class="tags-links">' . $tag_list . '</span>';
 495          }
 496  
 497          // Post author
 498          if ( 'post' == get_post_type() ) {
 499              printf(
 500                  '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
 501                  esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
 502                  /* translators: %s: Author display name. */
 503                  esc_attr( sprintf( __( 'View all posts by %s', 'twentythirteen' ), get_the_author() ) ),
 504                  get_the_author()
 505              );
 506          }
 507      }
 508  endif;
 509  
 510  if ( ! function_exists( 'twentythirteen_entry_date' ) ) :
 511      /**
 512       * Print HTML with date information for current post.
 513       *
 514       * Create your own twentythirteen_entry_date() to override in a child theme.
 515       *
 516       * @since Twenty Thirteen 1.0
 517       *
 518       * @param boolean $echo (optional) Whether to echo the date. Default true.
 519       * @return string The HTML-formatted post date.
 520       */
 521  	function twentythirteen_entry_date( $echo = true ) {
 522          if ( has_post_format( array( 'chat', 'status' ) ) ) {
 523              /* translators: 1: Post format name, 2: Date. */
 524              $format_prefix = _x( '%1$s on %2$s', '1: post format name. 2: date', 'twentythirteen' );
 525          } else {
 526              $format_prefix = '%2$s';
 527          }
 528  
 529          $date = sprintf(
 530              '<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span>',
 531              esc_url( get_permalink() ),
 532              /* translators: %s: Post title. */
 533              esc_attr( sprintf( __( 'Permalink to %s', 'twentythirteen' ), the_title_attribute( 'echo=0' ) ) ),
 534              esc_attr( get_the_date( 'c' ) ),
 535              esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
 536          );
 537  
 538          if ( $echo ) {
 539              echo $date;
 540          }
 541  
 542          return $date;
 543      }
 544  endif;
 545  
 546  if ( ! function_exists( 'twentythirteen_the_attached_image' ) ) :
 547      /**
 548       * Print the attached image with a link to the next attached image.
 549       *
 550       * @since Twenty Thirteen 1.0
 551       */
 552  	function twentythirteen_the_attached_image() {
 553          /**
 554           * Filter the image attachment size to use.
 555           *
 556           * @since Twenty thirteen 1.0
 557           *
 558           * @param array $size {
 559           *     @type int The attachment height in pixels.
 560           *     @type int The attachment width in pixels.
 561           * }
 562           */
 563          $attachment_size     = apply_filters( 'twentythirteen_attachment_size', array( 724, 724 ) );
 564          $next_attachment_url = wp_get_attachment_url();
 565          $post                = get_post();
 566  
 567          /*
 568           * Grab the IDs of all the image attachments in a gallery so we can get the URL
 569           * of the next adjacent image in a gallery, or the first image (if we're
 570           * looking at the last image in a gallery), or, in a gallery of one, just the
 571           * link to that image file.
 572           */
 573          $attachment_ids = get_posts(
 574              array(
 575                  'post_parent'    => $post->post_parent,
 576                  'fields'         => 'ids',
 577                  'numberposts'    => -1,
 578                  'post_status'    => 'inherit',
 579                  'post_type'      => 'attachment',
 580                  'post_mime_type' => 'image',
 581                  'order'          => 'ASC',
 582                  'orderby'        => 'menu_order ID',
 583              )
 584          );
 585  
 586          // If there is more than 1 attachment in a gallery...
 587          if ( count( $attachment_ids ) > 1 ) {
 588              foreach ( $attachment_ids as $idx => $attachment_id ) {
 589                  if ( $attachment_id == $post->ID ) {
 590                      $next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ];
 591                      break;
 592                  }
 593              }
 594  
 595              // get the URL of the next image attachment...
 596              if ( $next_id ) {
 597                  $next_attachment_url = get_attachment_link( $next_id );
 598              } else {
 599                  // or get the URL of the first image attachment.
 600                  $next_attachment_url = get_attachment_link( reset( $attachment_ids ) );
 601              }
 602          }
 603  
 604          printf(
 605              '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>',
 606              esc_url( $next_attachment_url ),
 607              the_title_attribute( array( 'echo' => false ) ),
 608              wp_get_attachment_image( $post->ID, $attachment_size )
 609          );
 610      }
 611  endif;
 612  
 613  /**
 614   * Return the post URL.
 615   *
 616   * @uses get_url_in_content() to get the URL in the post meta (if it exists) or
 617   * the first link found in the post content.
 618   *
 619   * Falls back to the post permalink if no URL is found in the post.
 620   *
 621   * @since Twenty Thirteen 1.0
 622   *
 623   * @return string The Link format URL.
 624   */
 625  function twentythirteen_get_link_url() {
 626      $content = get_the_content();
 627      $has_url = get_url_in_content( $content );
 628  
 629      return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
 630  }
 631  
 632  if ( ! function_exists( 'twentythirteen_excerpt_more' ) && ! is_admin() ) :
 633      /**
 634       * Replaces "[...]" (appended to automatically generated excerpts) with ...
 635       * and a Continue reading link.
 636       *
 637       * @since Twenty Thirteen 1.4
 638       *
 639       * @param string $more Default Read More excerpt link.
 640       * @return string Filtered Read More excerpt link.
 641       */
 642  	function twentythirteen_excerpt_more( $more ) {
 643          $link = sprintf(
 644              '<a href="%1$s" class="more-link">%2$s</a>',
 645              esc_url( get_permalink( get_the_ID() ) ),
 646              /* translators: %s: Post title. */
 647              sprintf( __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'twentythirteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
 648          );
 649          return ' &hellip; ' . $link;
 650      }
 651      add_filter( 'excerpt_more', 'twentythirteen_excerpt_more' );
 652  endif;
 653  
 654  /**
 655   * Extend the default WordPress body classes.
 656   *
 657   * Adds body classes to denote:
 658   * 1. Single or multiple authors.
 659   * 2. Active widgets in the sidebar to change the layout and spacing.
 660   * 3. When avatars are disabled in discussion settings.
 661   *
 662   * @since Twenty Thirteen 1.0
 663   *
 664   * @param array $classes A list of existing body class values.
 665   * @return array The filtered body class list.
 666   */
 667  function twentythirteen_body_class( $classes ) {
 668      if ( ! is_multi_author() ) {
 669          $classes[] = 'single-author';
 670      }
 671  
 672      if ( is_active_sidebar( 'sidebar-2' ) && ! is_attachment() && ! is_404() ) {
 673          $classes[] = 'sidebar';
 674      }
 675  
 676      if ( ! get_option( 'show_avatars' ) ) {
 677          $classes[] = 'no-avatars';
 678      }
 679  
 680      return $classes;
 681  }
 682  add_filter( 'body_class', 'twentythirteen_body_class' );
 683  
 684  /**
 685   * Adjust content_width value for video post formats and attachment templates.
 686   *
 687   * @since Twenty Thirteen 1.0
 688   */
 689  function twentythirteen_content_width() {
 690      global $content_width;
 691  
 692      if ( is_attachment() ) {
 693          $content_width = 724;
 694      } elseif ( has_post_format( 'audio' ) ) {
 695          $content_width = 484;
 696      }
 697  }
 698  add_action( 'template_redirect', 'twentythirteen_content_width' );
 699  
 700  /**
 701   * Add postMessage support for site title and description for the Customizer.
 702   *
 703   * @since Twenty Thirteen 1.0
 704   *
 705   * @param WP_Customize_Manager $wp_customize Customizer object.
 706   */
 707  function twentythirteen_customize_register( $wp_customize ) {
 708      $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
 709      $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
 710      $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
 711  
 712      if ( isset( $wp_customize->selective_refresh ) ) {
 713          $wp_customize->selective_refresh->add_partial(
 714              'blogname',
 715              array(
 716                  'selector'            => '.site-title',
 717                  'container_inclusive' => false,
 718                  'render_callback'     => 'twentythirteen_customize_partial_blogname',
 719              )
 720          );
 721          $wp_customize->selective_refresh->add_partial(
 722              'blogdescription',
 723              array(
 724                  'selector'            => '.site-description',
 725                  'container_inclusive' => false,
 726                  'render_callback'     => 'twentythirteen_customize_partial_blogdescription',
 727              )
 728          );
 729      }
 730  }
 731  add_action( 'customize_register', 'twentythirteen_customize_register' );
 732  
 733  /**
 734   * Render the site title for the selective refresh partial.
 735   *
 736   * @since Twenty Thirteen 1.9
 737   * @see twentythirteen_customize_register()
 738   *
 739   * @return void
 740   */
 741  function twentythirteen_customize_partial_blogname() {
 742      bloginfo( 'name' );
 743  }
 744  
 745  /**
 746   * Render the site tagline for the selective refresh partial.
 747   *
 748   * @since Twenty Thirteen 1.9
 749   * @see twentythirteen_customize_register()
 750   *
 751   * @return void
 752   */
 753  function twentythirteen_customize_partial_blogdescription() {
 754      bloginfo( 'description' );
 755  }
 756  
 757  /**
 758   * Enqueue Javascript postMessage handlers for the Customizer.
 759   *
 760   * Binds JavaScript handlers to make the Customizer preview
 761   * reload changes asynchronously.
 762   *
 763   * @since Twenty Thirteen 1.0
 764   */
 765  function twentythirteen_customize_preview_js() {
 766      wp_enqueue_script( 'twentythirteen-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20141120', true );
 767  }
 768  add_action( 'customize_preview_init', 'twentythirteen_customize_preview_js' );
 769  
 770  /**
 771   * Modifies tag cloud widget arguments to display all tags in the same font size
 772   * and use list format for better accessibility.
 773   *
 774   * @since Twenty Thirteen 2.3
 775   *
 776   * @param array $args Arguments for tag cloud widget.
 777   * @return array The filtered arguments for tag cloud widget.
 778   */
 779  function twentythirteen_widget_tag_cloud_args( $args ) {
 780      $args['largest']  = 22;
 781      $args['smallest'] = 8;
 782      $args['unit']     = 'pt';
 783      $args['format']   = 'list';
 784  
 785      return $args;
 786  }
 787  add_filter( 'widget_tag_cloud_args', 'twentythirteen_widget_tag_cloud_args' );
 788  
 789  /**
 790   * Prevents `author-bio.php` partial template from interfering with rendering
 791   * an author archive of a user with the `bio` username.
 792   *
 793   * @since Twenty Thirteen 3.0
 794   *
 795   * @param string $template Template file.
 796   * @return string Replacement template file.
 797   */
 798  function twentythirteen_author_bio_template( $template ) {
 799      if ( is_author() ) {
 800          $author = get_queried_object();
 801          if ( $author instanceof WP_User && 'bio' === $author->user_nicename ) {
 802              // Use author templates if exist, fall back to template hierarchy otherwise.
 803              return locate_template( array( "author-{$author->ID}.php", 'author.php' ) );
 804          }
 805      }
 806  
 807      return $template;
 808  }
 809  add_filter( 'author_template', 'twentythirteen_author_bio_template' );
 810  
 811  if ( ! function_exists( 'wp_body_open' ) ) :
 812      /**
 813       * Fire the wp_body_open action.
 814       *
 815       * Added for backwards compatibility to support pre 5.2.0 WordPress versions.
 816       *
 817       * @since Twenty Thirteen 2.8
 818       */
 819  	function wp_body_open() {
 820          /**
 821           * Triggered after the opening <body> tag.
 822           *
 823           * @since Twenty Thirteen 2.8
 824           */
 825          do_action( 'wp_body_open' );
 826      }
 827  endif;


Generated: Tue Oct 22 08:20:01 2019 Cross-referenced by PHPXref 0.7