[ Index ]

PHP Cross Reference of WordPress

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


Generated: Sat Nov 28 01:00:03 2020 Cross-referenced by PHPXref 0.7.1