functions.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /**
  3. * Sketch functions and definitions
  4. *
  5. * @package Sketch
  6. */
  7. /**
  8. * Set the content width based on the theme's design and stylesheet.
  9. */
  10. if ( ! isset( $content_width ) ) {
  11. $content_width = 764; /* pixels */
  12. }
  13. if ( ! function_exists( 'sketch_content_width' ) ) :
  14. function sketch_content_width() {
  15. global $content_width;
  16. if ( is_page_template( 'fullwidth-page.php' ) || ! is_active_sidebar( 'sidebar-1' ) ) {
  17. $content_width = 1091;
  18. }
  19. }
  20. endif;
  21. add_action( 'template_redirect', 'sketch_content_width' );
  22. if ( ! function_exists( 'sketch_setup' ) ) :
  23. /**
  24. * Sets up theme defaults and registers support for various WordPress features.
  25. *
  26. * Note that this function is hooked into the after_setup_theme hook, which
  27. * runs before the init hook. The init hook is too late for some features, such
  28. * as indicating support for post thumbnails.
  29. */
  30. function sketch_setup() {
  31. /*
  32. * Make theme available for translation.
  33. * Translations can be filed in the /languages/ directory.
  34. * If you're building a theme based on Sketch, use a find and replace
  35. * to change 'sketch' to the name of your theme in all the template files
  36. */
  37. load_theme_textdomain( 'sketch', get_template_directory() . '/languages' );
  38. // Add default posts and comments RSS feed links to head.
  39. add_theme_support( 'automatic-feed-links' );
  40. /*
  41. * Let WordPress manage the document title.
  42. * By adding theme support, we declare that this theme does not use a
  43. * hard-coded <title> tag in the document head, and expect WordPress to
  44. * provide it for us.
  45. */
  46. add_theme_support( 'title-tag' );
  47. /*
  48. * Enable support for Post Thumbnails on posts and pages.
  49. *
  50. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  51. */
  52. add_theme_support( 'post-thumbnails' );
  53. add_image_size( 'sketch-landscape', '800', '600', true );
  54. add_image_size( 'sketch-portrait', '800', '1067', true );
  55. add_image_size( 'sketch-square', '800', '800', true );
  56. add_image_size( 'sketch-featured', '1092', '400', true );
  57. add_image_size( 'sketch-site-logo', '300', '300' );
  58. // This theme uses wp_nav_menu() in one location.
  59. register_nav_menus( array(
  60. 'primary' => __( 'Primary Menu', 'sketch' ),
  61. 'social' => __( 'Social Links', 'sketch' ),
  62. ) );
  63. /*
  64. * Switch default core markup for search form, comment form, and comments
  65. * to output valid HTML5.
  66. */
  67. add_theme_support( 'html5', array(
  68. 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
  69. ) );
  70. /*
  71. * Enable support for Post Formats.
  72. * See http://codex.wordpress.org/Post_Formats
  73. */
  74. add_theme_support( 'post-formats', array(
  75. 'aside', 'image', 'video', 'quote', 'link'
  76. ) );
  77. // Set up the WordPress core custom background feature.
  78. add_theme_support( 'custom-background', apply_filters( 'sketch_custom_background_args', array(
  79. 'default-color' => 'eeeeee',
  80. 'default-image' => '',
  81. ) ) );
  82. /**
  83. * Add support for Eventbrite.
  84. * See: https://wordpress.org/plugins/eventbrite-api/
  85. */
  86. add_theme_support( 'eventbrite' );
  87. }
  88. endif; // sketch_setup
  89. add_action( 'after_setup_theme', 'sketch_setup' );
  90. /**
  91. * Register widget area.
  92. *
  93. * @link http://codex.wordpress.org/Function_Reference/register_sidebar
  94. */
  95. function sketch_widgets_init() {
  96. register_sidebar( array(
  97. 'name' => __( 'Sidebar', 'sketch' ),
  98. 'id' => 'sidebar-1',
  99. 'description' => '',
  100. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  101. 'after_widget' => '</aside>',
  102. 'before_title' => '<h1 class="widget-title">',
  103. 'after_title' => '</h1>',
  104. ) );
  105. }
  106. add_action( 'widgets_init', 'sketch_widgets_init' );
  107. /**
  108. * Enqueue scripts and styles.
  109. */
  110. function sketch_scripts() {
  111. wp_enqueue_style( 'sketch-style', get_stylesheet_uri() );
  112. wp_enqueue_style( 'sketch-lato', sketch_fonts_url(), array(), null );
  113. wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
  114. if ( sketch_has_featured_posts( 2 ) && is_page_template( 'portfolio-page.php' ) ) {
  115. wp_enqueue_script( 'sketch-flexslider', get_template_directory_uri() . '/js/jquery.flexslider.js', array( 'jquery' ), '20150811', true );
  116. wp_enqueue_script( 'sketch-script', get_template_directory_uri() . '/js/sketch.js', array( 'jquery' ), '20140530', true );
  117. }
  118. wp_enqueue_script( 'sketch-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
  119. if ( is_post_type_archive( 'jetpack-portfolio' ) || is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag' ) ) {
  120. wp_enqueue_script( 'sketch-portfolio', get_template_directory_uri() . '/js/portfolio.js', array( 'jquery' ), '20150708', true );
  121. }
  122. wp_enqueue_script( 'sketch-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  123. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  124. wp_enqueue_script( 'comment-reply' );
  125. }
  126. }
  127. add_action( 'wp_enqueue_scripts', 'sketch_scripts' );
  128. /**
  129. * Register Google Fonts
  130. */
  131. function sketch_fonts_url() {
  132. $fonts_url = '';
  133. /* Translators: If there are characters in your language that are not
  134. * supported by Lato, translate this to 'off'. Do not translate
  135. * into your own language.
  136. */
  137. $lato = _x( 'on', 'Lato font: on or off', 'sketch' );
  138. if ( 'off' !== $lato ) {
  139. $font_families = array();
  140. $font_families[] = 'Lato:300,400,700,300italic,400italic,700italic';
  141. $query_args = array(
  142. 'family' => urlencode( implode( '|', $font_families ) ),
  143. 'subset' => urlencode( 'latin,latin-ext' ),
  144. );
  145. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  146. }
  147. return $fonts_url;
  148. }
  149. /**
  150. * Enqueue Google Fonts for custom headers
  151. */
  152. function sketch_admin_scripts() {
  153. wp_enqueue_style( 'sketch-lato', sketch_fonts_url(), array(), null );
  154. }
  155. add_action( 'admin_print_styles-appearance_page_custom-header', 'sketch_admin_scripts' );
  156. /**
  157. * Determine and return the appropriate thumbnail size
  158. */
  159. function sketch_post_thumbnail_class() {
  160. if ( 'portrait' == get_theme_mod( 'sketch_portfolio_thumbnail' ) ) :
  161. $thumbsize = 'sketch-portrait';
  162. elseif ( 'square' == get_theme_mod( 'sketch_portfolio_thumbnail' ) ) :
  163. $thumbsize = 'sketch-square';
  164. else :
  165. $thumbsize = 'sketch-landscape';
  166. endif;
  167. if ( ! has_post_thumbnail() )
  168. $thumbsize .= ' no-thumbnail';
  169. return $thumbsize;
  170. }
  171. /**
  172. * Use a pipe for Eventbrite meta separators.
  173. */
  174. function sketch_eventbrite_meta_separator() {
  175. return '<span class="sep"> | </span>';
  176. }
  177. add_filter( 'eventbrite_meta_separator', 'sketch_eventbrite_meta_separator' );
  178. /**
  179. * Implement the Custom Header feature.
  180. */
  181. require get_template_directory() . '/inc/custom-header.php';
  182. /**
  183. * Custom template tags for this theme.
  184. */
  185. require get_template_directory() . '/inc/template-tags.php';
  186. /**
  187. * Custom functions that act independently of the theme templates.
  188. */
  189. require get_template_directory() . '/inc/extras.php';
  190. /**
  191. * Customizer additions.
  192. */
  193. require get_template_directory() . '/inc/customizer.php';
  194. /**
  195. * Load Jetpack compatibility file.
  196. */
  197. require get_template_directory() . '/inc/jetpack.php';