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


Generated: Thu Oct 28 01:00:03 2021 Cross-referenced by PHPXref 0.7.1