[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Sat May 16 08:20:03 2026 Cross-referenced by PHPXref